Ios 使用firebase应用程序内消息在webview中打开链接

Ios 使用firebase应用程序内消息在webview中打开链接,ios,swift,webview,Ios,Swift,Webview,我的应用程序是一个webview应用程序 请向我解释,当我按下“Сцццц”按钮时,如何在我的webview应用程序中打开链接 现在,当我按下按钮时,链接重定向并在Safari中打开 该消息通过firebase应用程序内消息显示 多谢各位 import JXWebViewController import UIKit import Firebase import UserNotifications import FirebaseInAppMessaging @UIApplicationMain

我的应用程序是一个webview应用程序

请向我解释,当我按下“Сцццц”按钮时,如何在我的webview应用程序中打开链接

现在,当我按下按钮时,链接重定向并在Safari中打开

该消息通过firebase应用程序内消息显示

多谢各位

import JXWebViewController
import UIKit
import Firebase
import UserNotifications
import FirebaseInAppMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    let gcmMessageIDKey = "gcm_message_id"

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let url = URL(string: "https://kupi95.ru/")!

        let webViewController = JXWebViewController()
        webViewController.webView.load(URLRequest(url: url))


        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = webViewController
        window?.makeKeyAndVisible()

        FirebaseApp.configure()

        if #available(iOS 10.0, *) {
          // For iOS 10 display notification (sent via APNS)
          UNUserNotificationCenter.current().delegate = self

          let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
          UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
        } else {
          let settings: UIUserNotificationSettings =
          UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
          application.registerUserNotificationSettings(settings)
        }

        Messaging.messaging().delegate = self

        application.registerForRemoteNotifications()

        // Register the delegate with the InAppMessaging instance
        let myFiamDelegate = CardActionFiamDelegate()
        InAppMessaging.inAppMessaging().delegate = myFiamDelegate;

        return true
    }


    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        UIApplication.shared.applicationIconBadgeNumber = 0
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
      // If you are receiving a notification message while your app is in the background,
      // this callback will not be fired till the user taps on the notification launching the application.
      // TODO: Handle data of notification

      // With swizzling disabled you must let Messaging know about the message, for Analytics
      // Messaging.messaging().appDidReceiveMessage(userInfo)

      // Print message ID.
      if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
      }

      // Print full message.
      print(userInfo)
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
      // If you are receiving a notification message while your app is in the background,
      // this callback will not be fired till the user taps on the notification launching the application.
      // TODO: Handle data of notification

      // With swizzling disabled you must let Messaging know about the message, for Analytics
      // Messaging.messaging().appDidReceiveMessage(userInfo)

      // Print message ID.
      if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
      }

      // Print full message.
      print(userInfo)

      completionHandler(UIBackgroundFetchResult.newData)
    }

}

@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

  // Receive displayed notifications for iOS 10 devices.
  func userNotificationCenter(_ center: UNUserNotificationCenter,
                              willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    let userInfo = notification.request.content.userInfo

    // With swizzling disabled you must let Messaging know abouuserNotificationCentert the message, for Analytics
    // Messaging.messaging().appDidReceiveMessage(userInfo)

    // Print message ID.
    if let messageID = userInfo[gcmMessageIDKey] {
      print("Message ID: \(messageID)")
    }

    // Print full message.
    print(userInfo)

    // Change this to your preferred presentation option
    completionHandler([.alert])
  }

  func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    // Print message ID.
    if let messageID = userInfo[gcmMessageIDKey] {
      print("Message ID: \(messageID)")
    }

    // Print full message.
    print(userInfo)

    completionHandler()
  }
}

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
      print("Firebase registration token: \(fcmToken)")

      let dataDict:[String: String] = ["token": fcmToken]
      NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
      // TODO: If necessary send token to application server.
      // Note: This callback is fired at each app startup and whenever a new token is generated.
    }

    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
      print("Received data message: \(remoteMessage.appData)")
    }
}

进口基础 导入FirebaseInAppMessaging 导入JXWebViewController

类CardActionFiamDelegate:NSObject,InAppMessagingDisplayDelegate{

func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, with action: InAppMessagingAction) {
    // ...
    let webViewController = JXWebViewController()
    webViewController.webView.load(URLRequest(url: action.actionURL))
}

func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
                      dismissType: FIRInAppMessagingDismissType) {
    // ...
}

func impressionDetected(for inAppMessage: InAppMessagingDisplayMessage) {
    // ...
}

func displayError(for inAppMessage: InAppMessagingDisplayMessage, error: Error) {
    // ...
}
}

如果我理解正确的话。 It链接,可以帮助您:

看起来它可以用func
messageClicked


你们能展示一下代码,你们是怎么做到的吗?[link]对不起,我按照这个说明做了,但你们并没有回答这个问题。你到底是怎么做到的?你能发你的密码吗?还是别的?谢谢你!我试过你的解决办法,但没用。请看我的代码,我粘贴了它。你应该调试你的代码,看起来你只是用链接制作了JXWebViewController。不要表现出来。如果单击func messageClicked called,请让webViewController=JXWebViewController()webViewController.webView.load(URLRequest(url:action.actionURL))我不知道该怎么办。请解释一下我的步骤,你应该调试你的代码是如何工作的,如果你点击单元格会发生什么?是否运行func messageClicked?
func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, with action: InAppMessagingAction) {
    // open view controller with webview for action.actionURL
}