【问题标题】:Nativescript contact-list pluginNativescript 联系人列表插件
【发布时间】:2018-09-20 02:57:31
【问题描述】:

我正在使用带有 Angular 的 nativescript 来创建联系人列表应用程序,并且我正在使用 nativescript-contacts 插件 (https://www.npmjs.com/package/nativescript-contacts)。开发是在 mac high sierra 上的 ios 模拟器上完成的。 我遵循文档,一切顺利,直到我到达 newContact.save();点,我的应用程序变黑并退出。当 .save() 被注释掉时,我可以通过控制台记录 newContact 对象并查看它是否正确设置。

我的组件如下所示:

import { Component, OnInit, ViewChild } from "@angular/core";
import { Router } from '@angular/router’

import { NewCardService } from './newcard.service';
import * as Toast from 'nativescript-toast';

@Component({
 selector: "Contact",
 moduleId: module.id,
 templateUrl: "./contact.component.html",
 styleUrls: ["./contact-common.css", "./contact.component.css"]
})
export class ContactComponent implements OnInit {
    public first_name: string="";
    public last_name: string="";
    public profession: string="";
    public phone: number = null;
    public email: string="";


constructor( private router: Router,
             private appStorage: AppStorage,
             private newCardService: NewCardService
) { }

ngOnInit(): void {    }

submit(){
    const date = new Date();
    const newContact = {
        id:  this.last_name + date.getTime(),
        first_name : this.first_name,
        last_name : this.last_name,
        profession : this.profession,
        phone: this.phone,
        email: this.email
    }
    this.newCardService.saveToContactList(newContact)
    const toast = Toast.makeText("Saved!");
    toast.show();
    this.router.navigate(['home'])
}
}

保存联系人的服务如下所示:

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch';

import * as contacts from "nativescript-contacts";
import * as imageSource from "image-source" ;

@Injectable()
export class ContactService {

constructor(  private http: Http  ) { }

saveToContactList(contact) {
    var newContact = new contacts.Contact();
    newContact.name.given = contact.first_name;
    newContact.name.family = contact.last_name;
    newContact.phoneNumbers.push({ label: contacts.KnownLabel.WORK, value: contact.phone });
    newContact.organization = contact.profession
    newContact.photo = imageSource.fromFileOrResource(contact.cardPictureURL);
    newContact.save();
}
}

我曾尝试寻找解决此问题的方法,但没有成功。 提前谢谢!

【问题讨论】:

    标签: angular plugins nativescript


    【解决方案1】:

    这可能是因为最近的 iOS 版本更严格的权限要求。尝试在您的 app/App_Resources/iOS/Info.plist 中添加以下内容

    <key>NSContactsUsageDescription</key>
    <string>This app requires contacts access for whatever reason.</string>
    

    【讨论】:

    • 非常感谢!!就是这样。添加这个 sn-p,解决了这个问题。附言。抱歉延迟回复。
    猜你喜欢
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2010-12-26
    • 1970-01-01
    • 2015-12-21
    相关资源
    最近更新 更多