openURL在Share扩展中不起作用 [英] openURL doesn't work in Share extension
问题描述
尝试在iOS 8共享扩展程序中使用 [self.extensionContext openURL:... completionHandler:...];
打开包含的应用程序永远不会打开应用程序,并始终调用完成处理程序成功= NO。
Trying to use [self.extensionContext openURL:... completionHandler:...];
in an iOS 8 Share extension to open the containing app never opens the app, and always calls the completion handler with success = NO.
此处与动作扩展相同,但我认为共享扩展能够打开包含应用程序比动作扩展更合理。共享扩展的要点是上传一个可能很大的数据,并且在不打开应用程序的情况下执行此操作的唯一方法是通过 NSURLSession
,它只能执行HTTP( S)上传。但是应用程序可能希望通过与HTTP(S)上传不同的机制来共享内容。
Here is the same issue with Action extensions, but I think it is more reasonable for Share extensions to be able to open the containing app than Action extensions. The point of a Share extension is to upload a potentially large piece of data, and the only way to do that without opening the app is through NSURLSession
, which can only do HTTP(S) uploads. But an app may wish to share content through a different mechanism than HTTP(S) uploads.
Apple文档没有声明 openURL .. 。
不能用于任何特定类型的扩展。很难知道这是一个错误还是预期的行为。没有关于此的官方信息。
Apple documentation doesn't state that openURL...
cannot be used for any particular type of extension. It's hard to know whether this is a bug or intended behavior. There is no official information about this.
推荐答案
以下是一些可能的解决方法... 与共享扩展程序通信/打开包含应用程序
Here are some possible workarounds... Communicating with/opening Containing app from Share extension
实际工作的那些可以概括为:
The ones that actually work can be summed up as:
- 使用UIDocumentInteractionController并使用特殊扩展类型注册容器应用程序从您的扩展中打开容器应用程序
- 使用虚拟NSURLSessionTask获取
应用程序:handleEventsForBackgroundURLSession:completionHandler:
UIApplicationDelegate类的方法要调用的容器应用程序。然后,在该方法中,您可以调用[[UIApplication sharedApplication] openURL:url]
打开您想要的任何内容。
- Using a UIDocumentInteractionController and registering your container app with a special extension type to open your container app from your extension
- Using a dummy NSURLSessionTask to get the
application:handleEventsForBackgroundURLSession:completionHandler:
method of the UIApplicationDelegate class of your container app to be called. Then, in that method, you can call[[UIApplication sharedApplication] openURL:url]
to open whatever you want.
这些方法都不完美,但它们确实有效(不确定苹果是否会喜欢它们)。有关详细信息,请查看链接。希望这会有所帮助:)
Neither of these methods are perfect, but they do work (not sure if Apple would like them though). For more details you can check out the link. Hope this helps :)
编辑:你也可以按照所述使用UIWebView https://stackoverflow.com/a/24614589/3923882
这篇关于openURL在Share扩展中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!