我想知道是否可以從我的應用程序iOS 7中打開通訊錄應用程序。我會解釋一下,我想讓用戶選擇搜索通過聯繫人,然後點擊聯繫人被重定向到聯繫人應用程序與選定聯繫人的具體頁面 是可能的? 還有可能做到這一點與提醒和日曆事件?是否可以從我的應用程序中打開通訊錄應用程序iOS 7
3
A
回答
-1
這是可能的,這裏有一個例子:
.h文件中:
@interface PickViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate, UINavigationControllerDelegate>
@property (strong, nonatomic) ABPeoplePickerNavigationController *peoplePicker;
@end
.m文件:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
_peoplePicker.delegate = self;
}
- (IBAction)btnAdd:(id)sender
{
[self presentViewController:self.peoplePicker animated:YES completion:nil];
}
#pragma mark - ABPeoplePickerNavigationController Delegate
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(@"Name %@", name);
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return YES;
}
+4
問題是關於從應用程序內部打開「通訊錄」應用程序,而不是訪問應用程序內的聯繫人 – Abizern
-2
添加通訊錄框架的工作。
導入通訊錄/ AddressBook.h
然後,我有一個工作的例子:你必須按照更改代碼以您的需求:
-(void)loadContact
{
dispatch_async(dispatch_get_main_queue(), ^(void){
if (loadingView == nil) {
loadingView = [LoadingView loadingViewInSuperView:self.view];
}
});
ABAddressBookRef ab;
ab = ABAddressBookCreate();
int len = (int) ABAddressBookGetPersonCount(ab);
NSMutableArray *allPeople = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(ab);
int i;
for(i = 0; i < len ; i++)
{
// Initialize the dictionary
NSMutableDictionary *dictAddress = [[NSMutableDictionary alloc] init];
ABRecordRef person = (__bridge ABRecordRef)([allPeople objectAtIndex:i]);
[dictAddress setValue:@"0" forKey:@"sel"];
[dictAddress setValue:@"" forKey:@"FirstName"];
[dictAddress setValue:@"" forKey:@"LastName"];
[dictAddress setValue:@"" forKey:@"Name"];
[dictAddress setValue:@"" forKey:@"PhoneMobile"];
[dictAddress setValue:@"" forKey:@"PhoneHome"];
[dictAddress setValue:@"" forKey:@"PhoneWork"];
[dictAddress setValue:@"" forKey:@"CompanyName"];
[dictAddress setValue:@"" forKey:@"AddressCity"];
[dictAddress setValue:@"" forKey:@"AddressCountry"];
[dictAddress setValue:@"" forKey:@"AddressState"];
[dictAddress setValue:@"" forKey:@"AddressCountryCode"];
[dictAddress setValue:@"" forKey:@"AddressStreet"];
[dictAddress setValue:@"" forKey:@"AddressZipCode"];
[dictAddress setValue:@"" forKey:@"EmailWork"];
[dictAddress setValue:@"" forKey:@"EmailHome"];
[dictAddress setValue:@"" forKey:@"EmailOther"];
[dictAddress setValue:@"" forKey:@"URLWork"];
[dictAddress setValue:@"" forKey:@"URLHome"];
[dictAddress setValue:@"" forKey:@"URLOther"];
[dictAddress setValue:@"" forKey:@"Note"];
NSMutableString *xmlString = [NSMutableString string];
if(ABRecordCopyValue(person, kABPersonFirstNameProperty) != NULL)
{
[dictAddress setValue:(NSString*)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty)) forKey:@"FirstName"];
[xmlString appendString:(__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty)];
}
if(ABRecordCopyValue(person, kABPersonLastNameProperty) != NULL)
{
[dictAddress setValue:(__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty) forKey:@"LastName"];
[xmlString appendString:(__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty)];
}
[dictAddress setValue:xmlString forKey:@"Name"];
if(ABRecordCopyValue(person, kABPersonOrganizationProperty) != NULL)
{
CFStringRef company = ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(company)
{
[dictAddress setValue:(__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty) forKey:@"CompanyName"];
CFRelease(company);
}
}
if (ABRecordCopyValue(person, kABPersonPhoneProperty) != NULL)
{
ABMultiValueRef phones =(__bridge ABMultiValueRef)((__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty));
NSString* [email protected]"";
NSString* phoneLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++)
{
phoneLabel = (__bridge_transfer NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
//if([phoneLabel isEqualToString:@"_$!<Main>!$_"])
if([phoneLabel isEqualToString:@"_$!<Home>!$_"])
{
Str = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phones, i);
Str = [Str stringByReplacingOccurrencesOfString:@"(" withString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@")" withString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@"-" withString:@""];
Str =[[Str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
[dictAddress setValue:Str forKey:@"PhoneHome"];
}
else if([phoneLabel isEqualToString:@"_$!<Mobile>!$_"])
{
Str = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phones, i);
Str = [Str stringByReplacingOccurrencesOfString:@"(" withString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@")" withString:@""];
Str =[[Str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@"-" withString:@""];
[dictAddress setValue:Str forKey:@"PhoneMobile"];
}
//else if([phoneLabel isEqualToString:@"_$!<Other>!$_"])
else if([phoneLabel isEqualToString:@"_$!<Work>!$_"])
{
Str = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phones, i);
Str = [Str stringByReplacingOccurrencesOfString:@"(" withString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@")" withString:@""];
Str =[[Str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
Str = [Str stringByReplacingOccurrencesOfString:@"-" withString:@""];
[dictAddress setValue:Str forKey:@"PhoneWork"];
}
}
CFRelease(phones);
}
if (ABRecordCopyValue(person, kABPersonAddressProperty) != NULL)
{
//Person address
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty);
if(ABMultiValueGetCount(addresses) != 0)
{
for(int i=0;i<ABMultiValueGetCount(addresses);i++)
{
CFStringRef address = ABMultiValueCopyValueAtIndex(addresses, i);
NSString *StrCity = [NSString stringWithFormat:@"%@", [(__bridge NSDictionary*)address objectForKey:@"City"]];
[dictAddress setValue:StrCity forKey:@"AddressCity"];
NSString *StrCountry = [NSString stringWithFormat:@"%@", [ (__bridge
NSDictionary*)address objectForKey:@"Country"]];
[dictAddress setValue:StrCountry forKey:@"AddressCountry"];
NSString *StrState = [NSString stringWithFormat:@"%@",[(__bridge NSDictionary*)address objectForKey:@"State"]];
[dictAddress setValue:StrState forKey:@"AddressState"];
NSString *StrCountryCode = [NSString stringWithFormat:@"%@",[(__bridge NSDictionary*)address objectForKey:@"CountryCode"]];
[dictAddress setValue:StrCountryCode forKey:@"AddressCountryCode"];
NSString *StrStreet = (NSString*)[(__bridge NSDictionary*)address objectForKey:@"Street"];
[dictAddress setValue:StrStreet forKey:@"AddressStreet"];
NSString *StrZip = [NSString stringWithFormat:@"%@",[(__bridge NSDictionary*)address objectForKey:@"ZIP"]];
[dictAddress setValue:StrZip forKey:@"AddressZipCode"];
}
}
else
CFRelease(addresses);
}
if (ABRecordCopyValue(person, kABPersonEmailProperty) != NULL)
{
//person email
NSString* emailLabel;
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
if(ABMultiValueGetCount(emails) != 0)
{
for(int i=0;i<ABMultiValueGetCount(emails);i++)
{
emailLabel = (__bridge_transfer NSString*)ABMultiValueCopyLabelAtIndex(emails, i);
if ([emailLabel isEqualToString:@"_$!<Work>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(emails, i)) forKey:@"EmailWork"];
}
else if([emailLabel isEqualToString:@"_$!<Home>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(emails, i)) forKey:@"EmailHome"];
}
else if([emailLabel isEqualToString:@"_$!<Other>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(emails, i)) forKey:@"EmailOther"];
}
}
}
else
CFRelease(emails);
}
if(ABRecordCopyValue(person, kABPersonURLProperty) != NULL)
{
NSString* URLLabel;
ABMultiValueRef urls = ABRecordCopyValue(person, kABPersonURLProperty);
if(ABMultiValueGetCount(urls) != 0)
{
for(int i=0;i<ABMultiValueGetCount(urls);i++)
{
URLLabel = (__bridge_transfer NSString*)ABMultiValueCopyLabelAtIndex(urls, i);
if ([URLLabel isEqualToString:@"_$!<Work>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(urls, i)) forKey:@"URLWork"];
}
else if([URLLabel isEqualToString:@"_$!<Home>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(urls, i)) forKey:@"URLHome"];
}
else if([URLLabel isEqualToString:@"_$!<Other>!$_"])
{
[dictAddress setValue:(__bridge id)(ABMultiValueCopyValueAtIndex(urls, i)) forKey:@"URLOther"];
}
}
}
}
if(ABRecordCopyValue(person, kABPersonNoteProperty) != NULL)
{
[dictAddress setValue:(__bridge NSString*)ABRecordCopyValue(person, kABPersonNoteProperty) forKey:@"Note"];
}
if (ABRecordCopyValue(person, kABPersonCreationDateProperty) != NULL)
{
[dictAddress setValue:(__bridge NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty) forKey:@"CreationDate"];
}
if (ABRecordCopyValue(person, kABPersonModificationDateProperty) != NULL)
{
[dictAddress setValue:(__bridge NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty) forKey:@"ModificationDate"];
}
/*
if (![[dictAddress valueForKey:@"EmailHome"] isEqualToString:@""] || ![[dictAddress valueForKey:@"EmailOther"] isEqualToString:@""] || ![[dictAddress valueForKey:@"EmailWork"] isEqualToString:@""])
{
dictAddress = nil;
}*/
NSLog(@"%@",dictAddress);
NSMutableArray *numberDict = [[NSMutableArray alloc]init];
if (![[dictAddress valueForKey:@"PhoneHome"] isEqualToString:@""]) {
// [numberDict setValue:[dictAddress valueForKey:@"PhoneHome"] forKey:@"PhoneHome"];
[numberDict addObject:[dictAddress valueForKey:@"PhoneHome"]];
}
if (![[dictAddress valueForKey:@"PhoneMobile"] isEqualToString:@""]) {
// [numberDict setValue:[dictAddress valueForKey:@"PhoneMobile"] forKey:@"PhoneMobile"];
[numberDict addObject:[dictAddress valueForKey:@"PhoneMobile"]];
}
if (![[dictAddress valueForKey:@"PhoneWork"] isEqualToString:@""]) {
[numberDict addObject:[dictAddress valueForKey:@"PhoneWork"]];
// [numberDict setValue:[dictAddress valueForKey:@"PhoneWork"] forKey:@"PhoneWork"];
}
[dictPhoneNumberFinal setObject:numberDict forKey:[dictAddress valueForKey:@"FirstName"]];
}
dispatch_async(dispatch_get_main_queue(), ^(void){
if (loadingView) {
[loadingView removeView];
loadingView = nil;
}
});
// arrContactNames = [[dictPhoneNumberFinal allKeys] mutableCopy];
arrContactNames =[[[dictPhoneNumberFinal allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] mutableCopy];
if(arrContactNames.count != 0)
{
[tblView reloadData];
// UIView *view = [[UIView alloc] initWithFrame:self.tableView.frame];
// [view setUserInteractionEnabled:FALSE];
//
// [view setBackgroundColor:[UIColor clearColor]];
// [self.tableView addSubview:view];
// [self.tableView setScrollEnabled:NO];
// [self addPopOverViewWithTag:1 :arrContactNames];
}
else{
[appDelegate userAlert:@"No contacts available."];
}
}
+4
問題是關於在應用程序內打開「通訊錄」應用程序,而不是訪問應用程序內的聯繫人。 – Abizern
相關問題
- 1. 是否可以遠程打開我的iOS應用程序?
- 2. 從我的iOS 5應用程序打開Twitter應用程序
- 3. 從iPhone iOS 7中的應用程序打開設置應用程序
- 4. 從iOS中的後臺應用程序打開應用程序?
- 5. 我可以從我的應用程序打開設置應用程序嗎?
- 6. 是否可以從網站的某些鏈接中打開iOS應用程序?
- 7. 從我的應用程序中打開iPod應用程序?
- 8. 可以從我的應用程序打開設置應用程序?
- 9. 是否可以從我的iPhone恢復iOS應用程序?
- 10. 是否可以從本機應用程序打開addContactScreen?
- 11. 是否可以從後臺應用程序打開Android屏幕?
- 12. 通過EMail打開IOS應用程序
- 13. 從通用Windows應用程序打開外部應用程序
- 14. 是否有可能通過我的ios應用程序直播到ustream而不是從ustream ios應用程序
- 15. 從通知中打開應用程序
- 16. 從我的應用程序打開Facebook應用程序
- 17. 從我的應用程序打開Foursquare應用程序
- 18. 如何從我的應用程序打開ola應用程序?
- 19. 從我的應用程序打開優步應用程序android
- 20. 從我的iPhone應用程序打開Spotify應用程序
- 21. 從我的應用程序打開另一個應用程序?
- 22. 打開一個應用程序從我的Android應用程序
- 23. 是否可以在我的應用程序iOS中從Skype獲取通知?
- 24. 是否可以在我的應用程序中的小窗口中打開應用程序?
- 25. 是否可以使用iPod爲iOS開發應用程序?
- 26. 從FB應用程序狀態(iOS)打開我的應用程序
- 27. 從URL打開應用程序 - ios 10
- 28. 從後臺打開iOS應用程序
- 29. 是否可以通過收件箱短信打開我的應用程序?
- 30. 檢查應用程序是否從推送通知中打開
您可以打開iOS中使用定製方案的任何應用程序。只需以編程方式搜索打開的聯繫人。 –
請告訴我這是怎麼回事 – Luca
快速的回答是,不,似乎沒有一個自定義的URL方案以編程方式打開'contacts.app'。請參閱http://stackoverflow.com/questions/3531585/is-there-a-custom-url-scheme-for-the-built-in-contacts-app - 這幾乎是這個問題的副本 – Petesh