Reputation: 99
i'm new to swift, i have created a today widget , and i added a button to that. in the Action of that button, i want to launch a url in safari, but "sharedApplication( )" doesn't working, i'm using this code in Normal view controller :
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.sharedApplication().openURL(NSURL(string: "facetime:[email protected]")!)
// Do any additional setup after loading the view, typically from a nib.
}
but its not working in Today App Extension.
Upvotes: 1
Views: 978
Reputation: 9825
You can't use sharedApplication
from an app extension.
Today widgets can open urls using the openUrl:completionHandler:
method on NSExtensionContext
, so you could do:
extensionContext?.openURL(NSURL(string: "facetime:[email protected]")!, completionHandler: nil)
You should be doing this in the tap handler for your button though, not in viewDidLoad
.
But note that the apple documentation states:
IMPORTANT
Apple allows any Today widget to use the openURL:completionHandler: method to open the widget’s own containing app.
If you employ this method to open other apps from your Today widget, your App Store submission might entail additional review to ensure compliance with the intent of Today widgets.
To learn more, read App Store Review Guidelines and iOS Human Interface Guidelines, linked to from Apple’s App Review Support page
Upvotes: 1
Reputation: 534893
This is well documented. There is no sharedApplication()
in a Today extension; the code isn't running in your app. In this particular situation, you can communicate with the NSExtensionContext instead.
Upvotes: 1