ios7.0 没法使用url调用系统应用吗
发布网友
发布时间:2023-08-07 23:23
我来回答
共1个回答
热心网友
时间:2023-08-08 02:54
由于ios系统对用户隐私的控制,第三方应用程序只能通过苹果官方接口调用系统通讯录,不能像android那样直接操作通讯录数据库。
一般地,使用系统自带通讯录的方法有两种,一种是直接将整个通讯录引入到应用程序,另一种是逐条读取通讯录中的每一条联系人信息。下面我们就一一详解。
1 直接引用整个通讯录
使用的类:ABPeoplePickerNavigationController
方法:
在LocalAddressBookController.h文件中
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface LocalAddressBookController : UIViewController<ABPersonViewControllerDelegate,ABPeoplePickerNavigationControllerDelegate,ABNewPersonViewControllerDelegate>
{
ABPeoplePickerNavigationController *picker;
ABNewPersonViewController *personViewController;
}
@end
在LocalAddressBookController.m文件中
#import "LocalAddressBookController.h"
#import "PublicHeader.h"
@implementation LocalAddressBookController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
picker = [[ABPeoplePickerNavigationController alloc]init];
picker.view.frame = CGRectMake(0, 0, Screen_width, Screen_height-48);
picker.peoplePickerDelegate = self;
picker.delegate = self; //为了隐藏右上角的“取消”按钮
[picker setHidesBottomBarWhenPushed:YES];
[picker setNavigationBarHidden:NO animated:NO];//显示上方的NavigationBar和搜索框
[self.view addSubview:picker.view];
}
#pragma mark UINavigationControllerDelegate methods
//隐藏“取消”按钮
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIView *custom = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,0.0f,0.0f)];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:custom];
[viewController.navigationItem setRightBarButtonItem:btn animated:NO];
[btn release];
[custom release];
}
#pragma mark - peoplePickerDelegate Methods
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
// [picker setNavigationBarHidden:NO animated:NO];
NSLog(@"%@", (NSString*)ABRecordCopyCompositeName(person));
return YES;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return YES;
}
-(BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return YES;
}
//“取消”按钮的委托响应方法
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
//assigning control back to the main controller
[picker dismissModalViewControllerAnimated:YES];
}
//……
@end