userNotificationCenter: didReceive: withCompletionHandler слишком короткий - PullRequest
0 голосов
/ 09 апреля 2019

userNotificationCenter: didReceive: withCompletionHandler вызывается, но приложение убивается очень быстро.

Приложение полностью убито, и я хочу отвечать на действие уведомления, не открывая приложение.Я пытался использовать семафор безуспешно.

    public init() {
        super.init()
        self.startBackgroundService()

        UNUserNotificationCenter.current().delegate = self
        Messaging.messaging().delegate = self
    }

    public func userNotificationCenter(_ center: UNUserNotificationCenter,
                                       didReceive response: UNNotificationResponse,
                                       withCompletionHandler completionHandler: @escaping () -> Void) {
        NSLog("userNotificationCenter:didReceive:withCompletionHandler")
        var data: [String: Any] = ["$": "NotificationResponse"]
        data["notification"] = response.notification.asDictionary()
        data["actionIdentifier"] = response.actionIdentifier
        data["backgroundDispatcher"] = getDispatcherHandle(key: "backgroundDispatcher")

        if let textResponse = response as? UNTextInputNotificationResponse {
            data["$"] = "TextInputNotificationResponse"
            data["userText"] = textResponse.userText
        }

        if (!initialized) {
            // wait for the service to initialize
            semaphore.wait();
        }

        self.background.invokeMethod("notificationResponse", arguments: data) { result in
            completionHandler()
            // the work is done, resume
            self.semaphore.resume();
        }

        // wait for the work to complete
        semaphore.wait();
    }

    private func startBackgroundService() {
        NSLog("startBackgroundService")
        internalQueue.sync {
            if (initialized) {
                return;
            }
        }
        if let info = FlutterCallbackCache.lookupCallbackInformation(getDispatcherHandle(key: "callbackDispatcher")) {
            backgroundRunner.run(withEntrypoint: info.callbackName, libraryURI: info.callbackLibraryPath)
            registrar.addMethodCallDelegate(self, channel: background)
            background.setMethodCallHandler { call, result in
                self.handle(call, result: result)
                // the service is initialized, resume
                self.semaphore.resume();
            }
        }
    }

Я также вижу это

Apr  9 02:43:19 Razvans-iPhone SpringBoard(UserNotificationsServer)[52] <Notice>: [com.tophap.firebaseNotificationsExample] Application background launch action for notification response action cancel recieved action response <BSActionResponse: 0x280f874a0; error: <NSError: 0x280757060; domain: BSActionErrorDomain; code: 1> {
    description = "The operation couldn\M-b\M^@\M^Yt be completed. (BSActionErrorDomain error 1.)";
}>
Apr  9 02:43:19 Razvans-iPhone SpringBoard(UserNotificationsServer)[52] <Notice>: [com.tophap.firebaseNotificationsExample] Removing process assertion for background notification action
...