美文网首页
iOS 常用小功能

iOS 常用小功能

作者: 一只代码狗 | 来源:发表于2017-11-13 15:49 被阅读24次
    • 打电话
      • [UIApplication sharedApplication] 的 openURL方法
      NSURL *url = [NSURL URLWithString:@"tel://10086"];
      if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
            [[UIApplication sharedApplication] openURL:url
                                               options:@{}
                                     completionHandler:nil];
       } else {
            [[UIApplication sharedApplication] openURL:url];
       }
      
      • 通过 webview 打开
        if (!_webview) {
            _webview = [[UIWebView alloc] initWithFrame:CGRectZero];
            [self.view addSubview:_webview];
        }
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10086"]];
        [_webview loadRequest:request];
      
    • 发短信
      • 打开 message 应用发送
        // 打开 message 发送,不可指定内容
        NSURL *url = [NSURL URLWithString:@"sms://10086"];
        [self openUrl:url];
      
      • MessageUI 内部发送短信,可指定任意内容
        // MessageUI 内部发送短信
        MFMessageComposeViewController *composeVC = [[MFMessageComposeViewController alloc] init];
        composeVC.body = @"套餐";
        composeVC.recipients = @[@"10086"];
        composeVC.messageComposeDelegate = self;
        [self presentViewController:composeVC animated:YES completion:nil];
      
    • 发邮件
      • 打开mail 应用发送
         // 打开自带的 mail 应用发送
        NSURL *url = [NSURL URLWithString:@"mailto://1292711060@qq.com"];
        [self openUrl:url];
      
      • MessageUI 应用内发送mail,若本机未登录绑定邮箱会奔溃!
        // MessageUI 内部发送mail
        MFMailComposeViewController *composeVC = [[MFMailComposeViewController alloc] init];
        if (composeVC == nil) {
            NSLog(@"尚未登录邮箱");
            return;
        }
        //composeVC.body = @"套餐";
        [composeVC setToRecipients:@[@"1292711060@qq.com"]];
        [composeVC setSubject:@"主题"];
        [composeVC setMessageBody:@"这是一封测试邮件" isHTML:NO];
        composeVC.mailComposeDelegate = self;
        
        UIImage *image = [UIImage imageNamed:@"0.jpg"];
        [composeVC addAttachmentData:UIImageJPEGRepresentation(image, 0.6) mimeType:@"" fileName:@"123.jpg"];
        
        [self presentViewController:composeVC animated:YES completion:nil];
      
    • 打开其他应用,如何查找 url schemes:
      • 下载他人的应用 ipa
      • 修改后缀名为 zip
      • 解压,打开 payload 文件夹
      • 右键 payload 文件夹 下的文件,显示包内容
      • 打开 info.plist 文件
      • url types 的 item0 的 url schemes
        NSURL *url = [NSURL URLWithString:@"weixin://"];
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
            [[UIApplication sharedApplication] openURL:url
                                               options:@{}
                                     completionHandler:nil];
        } else {
            [[UIApplication sharedApplication] openURL:url];
        }
    
    • App Store评分,上线时候每一个 app 会分配一个 appid
        NSString *appid = @"your appid";
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid]];
        [self openUrl:url];
    

    以上

    跪求Star

    相关文章

      网友评论

          本文标题:iOS 常用小功能

          本文链接:https://www.haomeiwen.com/subject/rhoamxtx.html