iOS呼叫撥號,簡訊,郵件,瀏覽器,AppStore,應用評分

weixin_34208283發表於2017-05-22

1.呼叫系統撥號

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:電話號碼"]];

2.呼叫系統簡訊

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://電話號碼"]];

2.1.如果要設定預設的簡訊內容

這個設定預設簡訊的時候,是在你的APP中會跳轉出一個簡訊的編輯介面,仍然在自己APP的介面裡面,並非跳轉到系統的簡訊介面
同時這個預設的內容使用者是可以修改過後在傳送的,相當於編輯狀態
// 匯入標頭檔案
#import <MessageUI/MFMessageComposeViewController.h>
// 新增代理
MFMessageComposeViewControllerDelegate
- (void)sendSMS{

    MFMessageComposeViewController *messageViewController = [[MFMessageComposeViewController alloc] init];
    messageViewController.messageComposeDelegate = self;

    if ([MFMessageComposeViewController canSendText]) {//判斷能否傳送簡訊
        messageViewController.recipients = @[@"手機號碼1",@"手機號碼2"]; // 新增收件人號碼,可以新增多個
        messageViewController.body = @"要傳送的簡訊內容"; // 要傳送的內容

        [self presentViewController:messageViewController animated:YES completion:nil];
    }
}
#pragma mark - MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

    //可以判斷簡訊傳送的結果
    if (result == MessageComposeResultCancelled) {
        NSLog(@"簡訊被取消");
    }else if (result == MessageComposeResultSent) {
        NSLog(@"簡訊傳送成功");
    }else if (result == MessageComposeResultFailed) {
        NSLog(@"簡訊傳送失敗");
    }
}

3.呼叫郵件

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://收件人郵箱"]];

3.1.設定預設的郵件內容
跟上面設定簡訊的預設內容一樣

// 匯入標頭檔案
#import <MessageUI/MFMailComposeViewController.h>
// 新增代理
MFMailComposeViewControllerDelegate
- (void)sendMail{

    MFMailComposeViewController * mcViewController = [[MFMailComposeViewController alloc] init];
    mcViewController.mailComposeDelegate = self;

    if ([MFMailComposeViewController canSendMail]) {
        // 收件人
        [mcViewController setToRecipients:@[@"郵箱地址1"]];
        // 抄送
        [mcViewController setCcRecipients:@[@"郵箱地址2",@"郵箱地址3"]];
        // 密送
        [mcViewController setBccRecipients:@[@"郵箱地址4"]];
        // 主題
        [mcViewController setSubject:@"郵件主題"];
        // 內容
        [mcViewController setMessageBody:@"郵件內容" isHTML:NO];

        [self presentViewController:mcViewController animated:YES completion:nil];
    }
}
#pragma mark - MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    if (result == MessageComposeResultCancelled) {
        NSLog(@"郵件被取消");
    }else if (result == MessageComposeResultSent) {
        NSLog(@"郵件傳送成功");
    }else if (result == MessageComposeResultFailed) {
        NSLog(@"郵件傳送失敗");
    }
}

4.呼叫safari

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://網址"]];

5.呼叫APPStore介面

跳轉到APPStore的下載介面的時候擁有兩種情況,都是可以跳轉的

5.1跳轉到APPStore 官方下載介面
1).以itms-apps://或https:// 開頭的應用詳情頁連結,跳轉到AppStore

//以itms-apps:為開頭,拼接下載地址
NSString *url = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",@"1014939463"];
//以https://為開頭,拼接下載地址
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",@"1014939463"];
//跳轉到appstore
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

2).以itms://為開頭的詳情連線,雖然是跳轉到 iTunes Store,但是開啟的仍然是應用的下載頁

//以itms://為頭拼接下載地址
NSString *url = [NSString stringWithFormat:@"itms://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",@"1014939463"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

6.跳轉到應用評分頁

此時以itms-apps://itms://開頭的連結都可以,而此時以https://開頭的連結不可以

NSString *url = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",@"1014939463"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

相關文章