iOS_常用的小功能

  • 打电话
NSString *telNumberStr = @"020-12345678";

// 方式一:在iOS10.1版本不会弹框提示,直接拨打电话。
NSString *telString = [[NSString alloc] initWithFormat:@"tel:%@",telNumberStr];

// 方式二:会弹框提示。
NSString *telString = [[NSString alloc] initWithFormat:@"telprompt://%@",telNumberStr];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
  • 发短信方式一:
NSString *url = @"sms://10086";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  • 发短信方式二:
1、导入框架:
#import <MessageUI/MessageUI.h>

2、遵循协议:
<MFMessageComposeViewControllerDelegate>

3、代码调用实现:
MFMessageComposeViewController *msgVC =[[MFMessageComposeViewController alloc] init];
// 设置短信内容
msgVC.body = @"一起玩耍吧";
// 设置收件人列表
msgVC.recipients = @[@"10086", @"10010"];
// 设置代理
msgVC.messageComposeDelegate = self;
// 显示控制器(self指代ViewController)
[self presentViewController:msgVC animated:YES completion:nil];

4、代理回调
#pragma mark - MFMessageComposeViewControllerDelegate
// 短信界面关闭后回调,会自动回到应用的页面
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    // 关闭短信页面
    [controller dismissViewControllerAnimated:YES completion:nil];
    // 返回短信结果
    if (result == MessageComposeResultCancelled) {
        NSLog(@"点击右上角、取消按钮");
    }
    if (result == MessageComposeResultSent) {
        NSLog(@"短信发送");
    }
    if (result == MessageComposeResultFailed) {
        NSLog(@"发送失败");
    }
}
  • 利用Safari打开链接
NSString *url = @"http://www.baidu.com";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  • 跳转至设置页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  • 跳转至AppStore详情页
NSString *appId = @"";
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@",appId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  • 跳转至AppStore评论页
NSString *appId = @"";
NSString *url = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software&id=%@",appId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值