AddressBook
AddressBook不能使用arc
- ABAddressBookRef 通訊錄對象
- ABRecordRef 聯繫人或羣組 ABRecordGetRecordType() ABRecordGetRecordID()
- ABPersonRef
- ABGroupRef
- ABPersonCreate():創建一個類型爲“kABPersonType”的ABRecordRef
- ABRecordCopyValue():取得指定屬性的值
- ABRecordCopyCompositeName():取得聯繫人(或羣組)的複合信息(對於聯繫人則包括:姓、名、公司等信息,對於羣組則返回組名稱)
- ABRecordSetValue():設置ABRecordRef的屬性值
- ABMutableMultiValueRef ABMultiValueAddValueAndLabel()方法依次添加屬性值
- ABRecordRemoveValue():刪除指定的屬性值
通訊錄的訪問步驟
- 調用ABAddressBookCreateWithOptions()方法創建通訊錄對象ABAddressBookRef。
- 調用ABAddressBookRequestAccessWithCompletion()方法獲得用戶授權訪問通訊錄
- 調用ABAddressBookCopyArrayOfAllPeople()、ABAddressBookCopyPeopleWithName()方法查詢聯繫人信息。
- 讀取聯繫人後如果要顯示聯繫人信息則可以調用ABRecord相關方法讀取相應的數據;如果要進行修改聯繫人信息,則可以使用對應的方法修改ABRecord信息,然後調用ABAddressBookSave()方法提交修改;如果要刪除聯繫人,則可以調用ABAddressBookRemoveRecord()方法刪除,然後調用ABAddressBookSave()提交修改操作
- 也就是說如果要修改或者刪除都需要首先查詢對應的聯繫人,然後修改或刪除後提交更改。如果用戶要增加一個聯繫人則不用進行查詢,直接調用ABPersonCreate()方法創建一個ABRecord然後設置具體的屬性,調用ABAddressBookAddRecord方法添加即可
系統應用
- 打電話:tel:或者tel://、telprompt:或telprompt://(撥打電話前有提示)
- 發短信:sms:或者sms://
- 發送郵件:mailto:或者mailto://
- 啓動瀏覽器:http:或者http://
-
//打電話 - (IBAction)callClicK:(UIButton *)sender { NSString *phoneNumber=@"18500138888"; // NSString *url=[NSString stringWithFormat:@"tel://%@",phoneNumber];//這種方式會直接撥打電話 NSString *url=[NSString stringWithFormat:@"telprompt://%@",phoneNumber];//這種方式會提示用戶確認是否撥打
系統服務
- 如果想要在應用程序內部完成這些操作則可以利用iOS中的MessageUI.framework,它提供了關於短信和郵件的UI接口供開發者在應用程序內部調用.在MessageUI.framework中主要有兩個控制器類分別用於發送短信(MFMessageComposeViewController)和郵件(MFMailComposeViewController),它們均繼承於UINavigationController。由於兩個類使用方法十分類似,這裏主要介紹一下MFMessageComposeViewController使用步驟:
- (IBAction)sendMessageClick:(UIButton *)sender { if([MFMessageComposeViewController canSendText]){ MFMessageComposeViewController *messageController=[[MFMessageComposeViewController alloc]init]; //收件人 messageController.recipients=[self.receivers.text componentsSeparatedByString:@","]; //信息正文 messageController.body=self.body.text; //設置代理,注意這裏不是delegate而是messageComposeDelegate messageController.messageComposeDelegate=self; //如果運行商支持主題 if([MFMessageComposeViewController canSendSubject]){ messageController.subject=self.subject.text; } //如果運行商支持附件 if ([MFMessageComposeViewController canSendAttachments]) { /*第一種方法*/ //messageController.attachments=...; /*第二種方法*/ NSArray *attachments= [self.attachments.text componentsSeparatedByString:@","]; if (attachments.count>0) { [attachments enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSString *path=[[NSBundle mainBundle]pathForResource:obj ofType:nil]; NSURL *url=[NSURL fileURLWithPath:path]; [messageController addAttachmentURL:url withAlternateFilename:obj]; }]; } /*第三種方法*/ // NSString *path=[[NSBundle mainBundle]pathForResource:@"photo.jpg" ofType:nil]; // NSURL *url=[NSURL fileURLWithPath:path]; // NSData *data=[NSData dataWithContentsOfURL:url]; /** * attatchData:文件數據 * uti:統一類型標識,標識具體文件類型,詳情查看:幫助文檔中System-Declared Uniform Type Identifiers * fileName:展現給用戶看的文件名稱 */ // [messageController addAttachmentData:data typeIdentifier:@"public.image" filename:@"photo.jpg"]; } [self presentViewController:messageController animated:YES completion:nil]; } } #pragma mark - MFMessageComposeViewController代理方法 //發送完成,不管成功與否 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ switch (result) { case MessageComposeResultSent: NSLog(@"發送成功."); break; case MessageComposeResultCancelled: NSLog(@"取消發送."); break; default: NSLog(@"發送失敗."); break; } [self dismissViewControllerAnimated:YES completion:nil]; }