在iOS 11.3中,didReceiveNotification函数没有调用tap

时间:2018-04-30 11:54:08

标签: ios swift4

在iOS 11.3及更高版本中,单击通知后,Mobiles didReceiveNotification函数未调用。它在iOS 9.3版本中正常运行。

在我的应用程序中,我想在应用程序上打开一个不同的视图控制器。基于通知类型。

我收到通知它插入数据库。但点击通知后,而不是打开所需的视图控制器只打开应用程序主屏幕。

但是在iOS 9中,所有功能都运行正常。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        let aps = userInfo[AnyHashable("gcm.notification.m")]

        if application.applicationState != .inactive{

        if(aps != nil){
            print(aps)
            self.insertNotification(data: "\(aps)")
         }
        }

        if application.applicationState == .active {

        }

        else if application.applicationState == .background{

        }

        else if application.applicationState == .inactive{

            let array: [Any] = ["\(aps)"]
            self.ns.set(array, forKey: "notify")

            var notification:String = "\(aps)"

            if let range = notification.range(of: "Optional") {
                notification.removeSubrange(range)
            }

            notification = String(notification.dropLast())
            notification = String(notification.dropFirst())

            let json:String = "\(notification)"
            let encodedString : NSData = (json as NSString).data(using: String.Encoding.utf8.rawValue)! as NSData

            do {
                var finalJSON = try JSON(data: encodedString as Data)

                var activityName:String!
                var url:String!
                var serviceUrl = LMUrl()

                if(finalJSON["Notify_Click"].dictionary != nil){
                    activityName = finalJSON["Notify_Click"]["activity_name"].string!
                    url = finalJSON["Notify_Click"]["url"].string!

                    if(activityName == "BuyLeads"){

                        let calWebURL: [String] = ["Buy Leads",serviceUrl.buyLeads+"\(url)&"]
                        ns.set(calWebURL, forKey: "web2")

                        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                        let initialViewController:webViewController = mainStoryboard.instantiateViewController(withIdentifier: "WebView") as! webViewController
                        let navi =  UINavigationController.init(rootViewController: initialViewController)
                        self.window?.rootViewController = navi
                        self.window?.makeKeyAndVisible()


                    }

                    else if(activityName == "RC"){
                        let calWebURL: [String] = ["Report Conversion",serviceUrl.reportConversion+"\(url)&"]
                        print(calWebURL)
                        ns.set(calWebURL, forKey: "web")

                        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                        let initialViewController:webViewController = mainStoryboard.instantiateViewController(withIdentifier: "WebView") as! webViewController
                        self.window?.rootViewController = initialViewController
                        self.window?.makeKeyAndVisible()
                    }
                    else{
                        print("no Action")
                    }
                }else{
                    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                    let initialViewController:notificationsViewController = mainStoryboard.instantiateViewController(withIdentifier: "notificationViewController") as! notificationsViewController
                    self.window?.rootViewController = initialViewController
                    self.window?.makeKeyAndVisible()

                }

            }catch{

            }


        }

        else{
            print("Notification")
        }


        completionHandler(.newData)
    }





    func insertNotification(data:String!){
        let FMDBInfo:Tbl_Info3 = Tbl_Info3()

        let dateFormatter : DateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let date = Date()
        let timestamp = dateFormatter.string(from: date)

        let time = DateFormatter.localizedString(from: NSDate() as Date, dateStyle: .medium, timeStyle: .short)
        //print(timestamp)

        FMDBInfo.notification = data as! String
        FMDBInfo.time = timestamp
        FMDBInfo.time2 = time

        print(FMDBInfo)

        let isInserted = FMDBDatabaseModel.getInstance().NotificationInsertData(FMDBInfo)
        if isInserted{
            print("Inserted")
        }else{
            print("Error while inserting data")
        }

    }

0 个答案:

没有答案