Push-уведомление не открывается NotificationsVC RXSwift - PullRequest
0 голосов
/ 10 июня 2019

Когда я нажимаю на баннеры, мое приложение открывается, но нет текущего VC, мне нужно открыть NotificationsVC.В Other VC я использую RXSwift.Где я могу добавить действие?

enum PushNotificationAction {
    case show
    case open
}


class PushManagerNotification {

    func convert(with value: [AnyHashable: Any], and state: PushNotificationAction) {
       ...
        guard let messageBody = dictionary["msg"] as? [String: AnyObject] else { return }

        if state == .show {
            showBadges(dictionary: messageBody)
            return
        }


        switch notificationType {
        case .notification:
            showNotification(dictionary: messageBody)
            break
        case .news:
            showNewsNotification(dictionary: messageBody)
            break
        default:
            break;
        }
    }


    private func showNotification(dictionary: [String:AnyObject]) {
        if let message = NotificationEntity(JSON: dictionary) {
            NotificationCenter.default.post(name: .notification, object: message);
        }
    }

    private func showNewsNotification(dictionary: [String:AnyObject]) {
        if let message = NewsNotificationEntity(JSON: dictionary) {
            NotificationCenter.default.post(name: .news, object: message);
        }
    }
}

в AppDelegate

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    pushManagerNotification.convert(with: userInfo, and: .open)
    completionHandler()
}

в didFinishLaunchingWithOptions:

    if let options = launchOptions, let remotePush = options[UIApplication.LaunchOptionsKey.remoteNotification], let accessToken = KeychainSwift().get(Constants.accessToken),let refreshToken = KeychainSwift().get(Constants.refreshToken) {
        let isLogin = UserDefaults.standard.bool(forKey: Constants.isLogin);
        if isLogin && !accessToken.isEmpty && !refreshToken.isEmpty{
            if let value = remotePush as? [AnyHashable:Any] {
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
                    self?.pushManagerNotification.convert(with: value, and: .open);
                }
            }
        }

    }
...