当应用被杀死时,点击Firebase通知无效(无效)

时间:2017-03-29 06:11:10

标签: ios iphone swift firebase notifications

我正在通过IOS,Swift3编写我的公司iphone应用程序。该应用有3个网页浏览量。当我的应用程序处于Forground和Background时,Firebase的通知运行良好。点击它时,我可以在webview上查看URL页面。当它处于非活动状态(杀死应用程序)时,我可以收到通知。但是点击它时,我无法查看URL页面,只能默认启动应用程序。 Plz告诉我智能解决方案。

这是我的AppDelegate的一部分。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    FIRMessaging.messaging().appDidReceiveMessage(userInfo)
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }
    print(userInfo)

    completionHandler(UIBackgroundFetchResult.newData)

    //notification tapping
    let openpUrl = userInfo["openURL"] as? String
    //let openpUrl = userInfo["openURL"] as? String
    if ((openpUrl?.range(of: "blog.naver.com")) != nil) {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "naverblogPushNotification"), object: userInfo)
    }else{
        if ((openpUrl?.range(of: "facebook.com")) != nil) {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "facebookPushNotification"), object: userInfo)
        }else{
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "inspotPushNotification"), object: userInfo)
        }
    }

}

以下是发送JASON

{"aps":{"alert":"Testing.. (40)","badge":1,"sound":"default"}, "openURL":"http://blog.naver.com/ins2020/22056541"}

我试图搜索此网站并关注它,但没有奏效。我很感激你的回答。

1 个答案:

答案 0 :(得分:0)

  

每当用户点击通知时。它可能在

     

UIApplicationStateActive

     

UIApplicationStateBackground

     

UIApplicationStateInactive

状态正确处理每个案例,您的问题将得到解决。

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{

            if(a    
pplication.applicationState == UIApplicationStateActive) {

            //app is currently active

        }else if(application.applicationState == UIApplicationStateBackground){

            //app is in background

        }else if(application.applicationState == UIApplicationStateInactive){

            //app is transitioning from background to foreground (user taps notification), do what you need when user taps here



           // Add your code to navigate to viewcontroller here..

        }
相关问题