I want to open the browser when the user taps a push notification.
In my app delegate I have:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var json = remoteNotif[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary
storyboard = UIStoryboard(name: "Main", bundle: nil)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let navC = storyboard.instantiateViewControllerWithIdentifier("mainNav") as! NavViewController
let data = json.objectForKey("data") as! NSDictionary
let url = data.objectForKey("url") as! String
UIApplication.sharedApplication().openURL(NSURL(string: url)!)
self.window?.rootViewController = navC
self.window?.makeKeyAndVisible()
}
When the user taps the push notification this gives me a black screen for 20 seconds, then the app opens, and then the browser opens. How can I make the tap on the push notification open only the browser, or at least open faster than 20 seconds?
Thank you.
Had the same issue although I am just opening an URL. The problem I was trying to open the URL (that's network task) without putting the code in a background thread. Just use this and it's opened right after the push notification is clicked:
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
UIApplication.sharedApplication().openURL(NSURL(string: "myURL")!)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With