1

I'm using Xcode 9.4.1. I have this code in AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.open(URL(string : "https://www.example.com")!, options: [:], completionHandler: { (status) in
    })
    return true
}

This will open https://www.example.com in Safari as soon, as I click on a push notification (or open the app) and it will also open my app.

Is there a way to open https://www.example.com in Safari without opening my app?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
David
  • 2,898
  • 3
  • 21
  • 57
  • 1
    I don’t think this is possible. Today extensions can open URLs as hey have access to an Extension Context which opens URLs in the same way an Application does, but I don’t think it is possible from a notification. – Chris Jul 01 '18 at 10:34
  • @Chris - You should add this as an answer – Paulw11 Jul 01 '18 at 11:10
  • @Paulw11 Thanks. I have added an answer. – Chris Jul 01 '18 at 11:52

1 Answers1

0

Unfortunately this is not possible. Today extensions can open URLs because they have access to an Extension Context which can open URLs the same way an Application can, but it is not possible from a notification.

Chris
  • 4,009
  • 3
  • 21
  • 52
  • Hey Chris, thank your for your answer. Is there a way to open either the app nor Safari when clicking on a push notification? – David Jul 01 '18 at 17:20
  • @David Do you mean so that the user would see nothing but that something would happen in background? – Chris Jul 01 '18 at 17:25
  • No, I mean: Don't do anything, don't open app, don't open Safari and don't do anything in background. Just inform the user about something with the push notification but don't do any action when clicking on it. Is it possible? – David Jul 01 '18 at 17:27
  • @David I think if the user taps on the notification then the app will always be opened. However, this question and its answers might be useful: https://stackoverflow.com/q/43214993/8289095 – Chris Jul 01 '18 at 17:30