Reputation: 379
I am using nativescript with angular to create a contact list application, and i am using the nativescript-contacts plugin (https://www.npmjs.com/package/nativescript-contacts). The development is done on ios emulator on mac high sierra. I follow the documentation, and all goes well until i reach the newContact.save(); point, at which my application goes black, and exits. When .save() is commented out, i can console log the newContact object and see that is properly set.
My component looks like so:
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'])
}
}
The service for saving the contact looks like so:
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();
}
}
I have tried looking for solution to this problem, with no luck. Thank you in advance!
Upvotes: 1
Views: 560
Reputation: 1119
This is probably because of the more strict permission request in recent iOS versions. Try adding the following in your app/App_Resources/iOS/Info.plist
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access for whatever reason.</string>
Upvotes: 1