大佬教程收集整理的这篇文章主要介绍了iOS8中的地址簿授权,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在iOS 7中,系统询问用户是否允许我的应用程序访问他的地址簿,但是因为iOS8没有任何请求.每次我在启动“MyGetAddressesOfContacts”函数之前检查ABAddressBookGetAuthorizationStatus时,Status等于kABAuthorizationStatusnotDetermined.
就像你在这里看到的:
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied) { UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"No permission" message:@"This App has no permition to access your contacts. Please check it in your privacy setTings of your device." delegate:self cancelButtontitle:@"OK" otherButtontitles: nil]; [alert show]; return nil; } // This AlertView pops up every time! if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusnotDetermined) { UIAlertView *alert = [[UIAlertView alloc] initWithtitle:@"Why this App needs your contacts" message:@"In the following your device will ask you whether this App is allowed to access your contacts. [...]" delegate:self cancelButtontitle:@"I understand" otherButtontitles: nil]; [alert show]; }
在此检查之后,我将启动MyGetAddressesOfContacts函数,如下所示:
ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *contactArr = (NSArray *)CFBridgingRelease(ABAddressBookCopyArrayOfallPeople(addressBook)); NSMutableDictionary *dPersons = [[NSMutableDictionary alloc] init]; for (int i = 0; i < [contactArr count]; i++) { ABRecordRef person = (ABRecordRef)CFBridgingRetain([contactArr objectATindex:i]); NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty); NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty); NSString *sPersonName = [NSString StringWithFormat:@"%@ %@",firstName,lastName]; ABMultiValueRef address = ABRecordCopyValue(person,kABPersonAddressProperty); NSString *sAddress; for(CFIndex j = 0; j < ABMultiValueGetCount(address); j++) { CFDictionaryRef addressDict = ABMultiValueCopyValueATindex(address,j); CFStringRef streetValue = CFDictionaryGetValue(addressDict,kABPersonAddressStreetKey); CFStringRef cityValue = CFDictionaryGetValue(addressDict,kABPersonAddressCityKey); CFStringRef countryValue = CFDictionaryGetValue(addressDict,kABPersonAddressCountryKey); sAddress = [NSString StringWithFormat:@"%@ %@,%@",streetValue,cityValue,countryValue]; [dPersons setObject:sAddress forKey: [NSString StringWithFormat:@"%@%d %ld",@"AddressFromnameID",i,j]]; } [dPersons setObject:sPersonName forKey: [NSString StringWithFormat:@"%@ %d",@"NameWithID",i]]; } return dPersons;
希望有人能提供帮助.
以上是大佬教程为你收集整理的iOS8中的地址簿授权全部内容,希望文章能够帮你解决iOS8中的地址簿授权所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。