ios系統服務

AddressBook

AddressBook不能使用arc

  1. ABAddressBookRef 通訊錄對象
  2. ABRecordRef 聯繫人或羣組 ABRecordGetRecordType() ABRecordGetRecordID()
  3. ABPersonRef
  4. ABGroupRef
  5. ABPersonCreate():創建一個類型爲“kABPersonType”的ABRecordRef
  6. ABRecordCopyValue():取得指定屬性的值
  7. ABRecordCopyCompositeName():取得聯繫人(或羣組)的複合信息(對於聯繫人則包括:姓、名、公司等信息,對於羣組則返回組名稱)
  8. ABRecordSetValue():設置ABRecordRef的屬性值
  9. ABMutableMultiValueRef ABMultiValueAddValueAndLabel()方法依次添加屬性值
  10. ABRecordRemoveValue():刪除指定的屬性值

通訊錄的訪問步驟

  1. 調用ABAddressBookCreateWithOptions()方法創建通訊錄對象ABAddressBookRef。
  2. 調用ABAddressBookRequestAccessWithCompletion()方法獲得用戶授權訪問通訊錄
  3. 調用ABAddressBookCopyArrayOfAllPeople()、ABAddressBookCopyPeopleWithName()方法查詢聯繫人信息。
  4. 讀取聯繫人後如果要顯示聯繫人信息則可以調用ABRecord相關方法讀取相應的數據;如果要進行修改聯繫人信息,則可以使用對應的方法修改ABRecord信息,然後調用ABAddressBookSave()方法提交修改;如果要刪除聯繫人,則可以調用ABAddressBookRemoveRecord()方法刪除,然後調用ABAddressBookSave()提交修改操作
  5. 也就是說如果要修改或者刪除都需要首先查詢對應的聯繫人,然後修改或刪除後提交更改。如果用戶要增加一個聯繫人則不用進行查詢,直接調用ABPersonCreate()方法創建一個ABRecord然後設置具體的屬性,調用ABAddressBookAddRecord方法添加即可

系統應用

  1. 打電話:tel:或者tel://、telprompt:或telprompt://(撥打電話前有提示)
  2. 發短信:sms:或者sms://
  3. 發送郵件:mailto:或者mailto://
  4. 啓動瀏覽器:http:或者http://
  5. //打電話
    - (IBAction)callClicK:(UIButton *)sender {
        NSString *phoneNumber=@"18500138888";
    //    NSString *url=[NSString stringWithFormat:@"tel://%@",phoneNumber];//這種方式會直接撥打電話
        NSString *url=[NSString stringWithFormat:@"telprompt://%@",phoneNumber];//這種方式會提示用戶確認是否撥打
    

    系統服務

    1. 如果想要在應用程序內部完成這些操作則可以利用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];
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章