【问题标题】:How to prevent OneSignal on IOS Swift to open WebView when handling notification如何防止 IOS Swift 上的 OneSignal 在处理通知时打开 WebView
【发布时间】:2018-07-27 04:55:23
【问题描述】:

我正在处理我原来的 webview 中的 lunchUrl,但问题是当我把 kOSSettingsKeyInAppLaunchURL

[true] 它会在我原来的 webview 上打开新的 webview

[false] 它会在 safary 中打开链接

let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
    let payload = result?.notification.payload
    if let additionalData = result!.notification.payload!.additionalData {
        // DEEP LINK and open url in RedViewController
        centerViewController.receivedURL = payload!.launchURL as! String!

        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = centerViewController
        self.window?.makeKeyAndVisible()
    }
}

OneSignal.initWithLaunchOptions(launchOptions, appId: "*****", handleNotificationReceived: { (notification) in
    }, handleNotificationAction: notificationOpenedBlock , settings: [kOSSettingsKeyAutoPrompt : true, kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.notification.rawValue, kOSSettingsKeyInAppLaunchURL: true])

【问题讨论】:

  • 嗨,你解决了吗?
  • 如果您不想使用默认的 OS Web 视图,请不要在通知中设置 url 字段。相反,您可以使用附加数据字段并在其中放置一个自定义 URL 字段。

标签: ios swift push-notification uiwebview onesignal


【解决方案1】:

尝试在 Appdelegate 中使用此代码:

let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
    // This block gets called when the user reacts to a notification received
    let payload: OSNotificationPayload = result!.notification.payload

    /// Check response message click notification in here
    var fullMessage = payload.body
    self.window?.rootViewController = UINavigationController(rootViewController: ViewController())

    }

    if payload.additionalData != nil {
        if payload.title != nil {
            let messageTitle = payload.title
            let additional = payload.additionalData["recive_id"] as! String
            print("tes aditional data: \(additional)")
            print("Message Title = \(messageTitle!)") //proses notif klik "3" Goto target
            if messageTitle == "id" {
                self.window?.rootViewController = UINavigationController(rootViewController: ViewController())
            }
        }

        let additionalData = payload.additionalData
        if additionalData?["actionSelected"] != nil {
            fullMessage = fullMessage! + "\nPressed ButtonID: \(String(describing: additionalData!["actionSelected"]))"
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2017-05-02
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多