今天如何从iOS 8打开应用程序扩展
问题描述:
我试图从通知中心的今天扩展程序中打开应用程序,我尝试过使用计划URL,但似乎我无法使用是在扩展中,因为:今天如何从iOS 8打开应用程序扩展
[UIApplication sharedapplication]
不起作用。我该怎么办?
答
这应该解决您的问题:
NSURL *url = [NSURL URLWithString:@"testMe://"];
[self.extensionContext openURL:url completionHandler:nil];
答
到故事板添加按钮,在扩展
添加CFBundleURLSchemes这样你就可以用网址 “weatherapp:” 打开的应用程序
呼叫的OpenURL
@IBAction func buttonOpen_Action(sender: AnyObject) {
/*
Add to APP Info.plist
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>weatherapp</string>
</array>
</dict>
</array>
</dict>
</plist>
*/
let context = self.extensionContext
if let url = NSURL(string:"weatherapp:"){
context?.openURL(url, completionHandler: { (Bool) -> Void in
print("weatherapp:open done.")
})
}else{
print("ERROR: weatherapp: not supported")
}
}