I am working on a chat application same as whatsapp. So I need same functionality when user disable/enable contact access (privacy setting) for my app. If the user disable or enable the contact in app setting. How can I be notify in the app. I need to keep track when user changes enable/disable contact settings (privacy setting). So i do reflect changes on each event in My App. And if anyone knows how whatsapp doing this.
Given below is the screenshots of whatsapp.
Case 1.Has Contact Access
Case 2 Don't Have Contact Access
答案 0 :(得分:1)
每次用户启动应用时,您都可以使用以下代码检查应用是否仍具有联系人权限:
#import <AddressBookUI/AddressBookUI.h>
- (void)applicationWillEnterForeground:(UIApplication *)application {
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
if (granted) {
// First time access has been granted
// Show 4 Tabs
} else {
// User denied access
// Show 3 Tabs
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
// Show 4 Tabs
}
else {
// The user has denied access
// Show only 3 Tabs
}
}
答案 1 :(得分:-1)
根据苹果公司的网站(在页面中间向下滚动到隐私),必须先授予对地址簿的访问权限,然后才能以编程方式进行访问。这就是我最终要做的事情 -
#import <AddressBookUI/AddressBookUI.h>
- (BOOL)isContactsFetchingAccessibleOrNot {
// Request authorization to Address Book
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
if (granted) {
// First time access has been granted, add the contact
//do something
} else {
// User denied access
// Display an alert telling user the contact could not be added
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
//do something
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
}
}
当app从后台到前台时,您也可以调用此方法。