App Extensions 打开 app
来源:互联网 发布:ps ef grep java 编辑:程序博客网 时间:2024/04/25 17:45
App Extensions里不能直接调用openurl的方式去打开app,sdk提供了一种方法:
// Asks the host to open an URL on the extension's behalf- (void)openURL:(NSURL *)URL completionHandler:(void (^ __nullable)(BOOL success))completionHandler;
但是这种方法目前只能适用于today extension(其他的extension暂时不可用)。
通过网上查找资料,目前搜集到两个方法:
第一种,sdk版本要8.3以上(包括8.3,9.2测试还可以用)
// Prepare the URL request // this will use the custom url scheme of your app // and the paths to the photos you want to share: NSString * urlString = [ NSString stringWithFormat: @"%@://%@", APP_SHARE_URL_SCHEME, ( NULL == invokeArgs ? @"" : invokeArgs ) ]; NSURL * url = [ NSURL URLWithString: urlString ]; NSString *className = @"UIApplication"; if ( NSClassFromString( className ) ) { id object = [ NSClassFromString( className ) performSelector: @selector( sharedApplication ) ]; [ object performSelector: @selector( openURL: ) withObject: url ]; }第二种,sdk版本低于8.3的
// openURL doesn't work for any extension, but the Today one, // so we'll use a workaround: // 1. Instantiate a UIWebView that's so tiny it won't show on the screen: UIWebView * webView = [ [ UIWebView alloc ] initWithFrame: CGRectMake( 0, 0, 0, 0 ) ]; // 2. Prepare the URL request for the UIWebView: // this will use the custom url scheme of your app // and the paths to the photos you want to share: NSString * urlString = [ NSString stringWithFormat: @"%@://%@", APP_SHARE_URL_SCHEME, ( NULL == invokeArgs ? @"" : invokeArgs ) ]; NSURL * url = [ NSURL URLWithString: urlString ]; NSURLRequest * request = [ NSURLRequest requestWithURL: url ]; // 3. Now get the UIWebView to load the request, which will launch the app: [ webView loadRequest: request ]; [ self.view addSubview: webView ]; // 4. And finally, say bye to the UIWebView. // The delay is important here, otherwise the UIWebView won't have time // to invoke your app before it's dismissed: [ webView performSelector: @selector( removeFromSuperview ) withObject: NULL afterDelay: 2.0 ];
以上主要方法来自http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/ 这篇文章
0 0
- App Extensions 打开 app
- App Extensions
- WWDC2014 IOS8 APP Extensions
- WWDC2014 IOS8 APP Extensions
- App Extensions学习笔记
- App Extensions学习笔记
- 一、iOS App Extensions
- WWDC2014之App Extensions (App功能共享)
- WWDC2014之App Extensions (App功能共享)
- WWDC2014之App Extensions (App功能共享)
- WWDC2014之App Extensions (App功能共享)
- App Extensions for iOS 8
- App Extensions 基本学习 iOS8
- app内部打开另一个app
- App内打开App Store
- WWDC2014之App Extensions学习笔记
- WWDC2014之App Extensions学习笔记
- WWDC2014之App Extensions学习笔记
- 2015年9月——2016年2月半年总结
- App集成ApplePay
- 数组和指针的区别
- Eclipse运行时提示“Failed to load the JNI shared library /Java/jre6/bin/client/jvm.dll”的一个解决方案
- Android Studio常用插件
- App Extensions 打开 app
- HTML之DOM
- unity 背景动态模糊(blur)和截屏方法
- Android Surface相关常见问题
- Linux平台总线驱动设备模型
- RadioButton去掉默认显示的圆圈
- lintcode:Delete Digits
- 用grep在文件中搜索文体的基本用法
- JVM内存结构浅析