在iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的 ##转...

源地址:http://blog.csdn.net/lengshengren/article/details/16339409

 

iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App。

通过openURL方法可以调用如下应用:

  • 调用谷歌地图(Google Maps)
  • 调用邮件客户端(Apple Mail)
  • 拨号(Phone Number)
  • 调用短信(SMS)
  • 调用浏览器(Safari Browser)
  • 调用应用商店(AppStore)

 

调用谷歌地图(Google Maps)

URL模式:http://maps.google.com/maps?q=<strong>${QUERY_STRING}</strong>

代码示例:

NSString* searchQuery =@"1 Infinite Loop, Cupertino, CA 95014";
searchQuery =[addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString =[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

 

 

调用邮件客户端(Apple Mail)

URL模式:mailto://<strong>${EMAIL_ADDRESS}</strong>

代码示例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@eyecm.com"]];

 

 

拨号(Phone Number)

URL模式:tel://<strong>${PHONE_NUMBER}</strong>

代码示例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];

 

可以跳转回来

NSString *phoneNum =[NSString stringWithFormat:@"%@",_model.contactWay];// 电话号码
NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
if ( !phoneCallWebView ) {
phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的控件 不需要add到页面上来 效果跟方法一样 但是这个方法是合法的
}
[phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];

 

 

调用短信(SMS)

URL模式:sms:<strong>${PHONENUMBER_OR_SHORTCODE}</strong>

代码示例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:10086"]];

 

 

调用浏览器(Safari Browser)

代码示例:

NSURL*url =[NSURL URLWithString:@"http://eyecm.com"];
[[UIApplication sharedApplication] openURL:url];

 

 

调用应用商店(AppStore)

URL模式:http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;mt=8

代码示例:

NSURL*appStoreUrl =[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;amp;mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];

转载于:https://www.cnblogs.com/KingQiangzi/p/3738494.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 10及以上版本,可以使用`UNUserNotificationCenterDelegate`协议的`userNotificationCenter(_:didReceive:withCompletionHandler:)`方法来接收到新通知。如果您想要在接收到新通知时删除以前发送的通知,可以使用`UNUserNotificationCenter`类提供的`removeDeliveredNotifications(withIdentifiers:)`方法。 具体实现如下: 1. 在您的`AppDelegate`类,将`UNUserNotificationCenterDelegate`设置为应用的通知心的代理: ``` class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let center = UNUserNotificationCenter.current() center.delegate = self // ... return true } } ``` 2. 实现`UNUserNotificationCenterDelegate`协议的`userNotificationCenter(_:didReceive:withCompletionHandler:)`方法: ``` func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let notificationIdentifier = response.notification.request.identifier let center = UNUserNotificationCenter.current() center.removeDeliveredNotifications(withIdentifiers: [notificationIdentifier]) completionHandler() } ``` 在这个方法,获取到`response`参数通知的唯一标识符,并使用`UNUserNotificationCenter`类的`removeDeliveredNotifications(withIdentifiers:)`方法来删除以前发送的通知。最后,一定要调用`completionHandler()`方法来告诉系统已经处理完通知了。 注意:这个方法只会在用户点击通知时被调用,如果用户直接在通知清除了通知,这个方法并不会被调用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值