[
https://issues.apache.org/jira/browse/CB-7838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14969314#comment-14969314
]
Matus P commented on CB-7838:
-----------------------------
Hi. I've found this problem on both (device and simulator). The problem is,
that native contacts picker is not asking user to grant permissions to access
address book. And it's seems, that because of it contact ID is set to -1 value.
So I changed iOS code to this in file CDVContacts.m for method
(void)chooseContact: ((CDVInvokedUrlCommand*)command:
{code}
NSString* callbackId = command.callbackId;
CDVAddressBookHelper* abHelper = [[CDVAddressBookHelper alloc] init];
CDVContacts* __weak weakSelf = self; // play it safe to avoid retain
cycles
// it gets uglier, block within block.....
[abHelper createAddressBook: ^(ABAddressBookRef addrBook,
CDVAddressBookAccessError* errCode) {
if (addrBook == NULL) {
// permission was denied or other error - return error
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:errCode ?
(int)errCode.errorCode:UNKNOWN_ERROR];
[weakSelf.commandDelegate sendPluginResult:result
callbackId:callbackId];
return;
}
/// HERE IS THE CURRENT CODE OF METHOD ///
}];
{code}
After applying, it asks for permissions first time I want to pick a Contact.
> Contact Picker returns -1 as the id for all contacts
> ----------------------------------------------------
>
> Key: CB-7838
> URL: https://issues.apache.org/jira/browse/CB-7838
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Contacts
> Affects Versions: 3.5.0
> Environment: iOS
> Reporter: Ralph S Theart
>
> Can anyone confirm that the contacts plug-in returns -1 for any contact id
> return from a device but it on the simulator returns a valid unique ID?
> Its strange..I have ios8 devices that return -1 for any contact picked...but
> the same action on the simulators returns a positive integer.
> {code:title=From iOS 8 Device|borderStyle=solid}
> {
> "id": -1,
> "rawId": null,
> "displayName": null,
> "name": {
> "givenName": "Aunte",
> "formatted": "Aunte Aline",
> "middleName": null,
> "familyName": "Aline",
> "honorificPrefix": null,
> "honorificSuffix": null
> },
> "nickname": null,
> "phoneNumbers": [
> {
> "type": "other",
> "value": "01141223*******",
> "id": 0,
> "pref": false
> }
> ],
> "emails": [
> {
> "type": "home",
> "value": "vito.******@bluewin.ch",
> "id": 0,
> "pref": false
> }
> ],.........
> {code}
> {code:title=From ios-sim}
> {
> "id": 7,
> "rawId": null,
> "displayName": null,
> "name": {
> "givenName": "Test",
> "formatted": "Test",
> "middleName": null,
> "familyName": null,
> "honorificPrefix": null,
> "honorificSuffix": null
> },
> "nickname": null,
> "phoneNumbers": [
> {
> "type": "home",
> "value": "(954)\u00a0646-7923",
> "id": 0,
> "pref": false
> }
> ],
> "emails": null,
> "addresses": null,
> "ims": null,
> "organizations": null,
> "birthday": null,
> "note": null,
> "photos": null,
> "categories": null,
> "urls": null
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]