参见英文答案 >
Programmatically Request Access to Contacts10个
我将所有本地通讯录联系人导入我的应用程序.目前,要求允许访问联系人的警报视图是在应用启动时完成的.
我将所有本地通讯录联系人导入我的应用程序.目前,要求允许访问联系人的警报视图是在应用启动时完成的.
如何更改它,因此在应用程序的其他地方要求许可?点击一个按钮,就像Instagram?
看到这张照片:
解决方法
您可以阅读文档
HERE.
这里有一些代码让你开始:
//First of all import the AddRessBookUI #import <AddressBookUI/AddressBookUI.h> // Request to authorise the app to use addressbook ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(nil,nil); if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { ABAddressBookRequestAccessWithCompletion(addressBookRef,^(bool granted,CFErrorRef error) { if (granted) { // If the app is authorized to access the first time then add the contact [self _addContactToAddressBook]; } else { // Show an alert here if user denies access telling that the contact cannot be added because you didn't allow it to access the contacts } }); } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { // If the user user has earlier provided the access,then add the contact [self _addContactToAddressBook]; } else { // If the user user has NOT earlier provided the access,create an alert to tell the user to go to Settings app and allow access }
这里有另外几个教程,您可能希望看到可以找到HERE和HERE.
希望这可以帮助!
更新:您必须使用didFinishLaunchingWithOptions检测您的应用程序第一次启动:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) { // The app has already launched once } else { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; [[NSUserDefaults standardUserDefaults] synchronize]; // This is the first time the app is launched } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。