I have a problem with requesting access to the Addressbook, because ABAddressbook.Create is always null.
So how can I request the Access?
NSError err = new NSError ();
ABAddressBook ab = ABAddressBook.Create(out err)
ab.RequestAccess (delegate {}); //ab always null
Thanks for help.
If it's null then something was wrong and your NSError should tell you what it is (btw there's no need to initialize an out parameter).
In general (iOS6+) your code should look like:
NSError err;
var ab = ABAddressBook.Create (out err);
if (err != null) {
// process error
return;
}
// if the app was not authorized then we need to ask permission
if (ABAddressBook.GetAuthorizationStatus () != ABAuthorizationStatus.Authorized) {
ab.RequestAccess (delegate (bool granted, NSError error) {
if (error != null) {
// process error
} else if (granted) {
// permission now granted -> use the address book
}
});
} else {
// permission already granted -> use the address book
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With