iOS 10 UNNotificationAction,可以从后台模式切换到前台模式吗?

问题描述 投票:0回答:1

UINotificationAction定义如下

let customAction = UNNotificationAction(identifier: "customCategory.Action", title: "Do something", options: [])

单击时,将发出Web服务请求以使用如下所示的UNUserNotificationCenterDelegate方法获取数据

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let actionIdentifier = response.actionIdentifier
    switch actionIdentifier {
    case customCategory.Action:
        if authTokenNotExpired {
            // Make service call
        } else {
            // Show login screen (In foreground)
        }

    }
    completionHandler()
}

但是应用程序已登录,并且当身份验证令牌过期时,Web服务请求失败。

根据要求,在这种故障情况下,应显示登录屏幕。

是否可以将应用程序从后台模式移动到前台以便显示登录屏幕?

ios swift push-notification ios10
1个回答
0
投票

您的问题与您要的问题有所不同。一种解决方案是在appdelegate中这样做:

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    NotificationCenter.default.addObserver(self, selector: #selector(triggerGetNewToken(note:)), name: .isNeedNewToken, object: nil)
  }

@objc func triggerGetNewToken(note:NSNotification){
    debugLog(logMessage: "GETTING NEW TOKENS NOW IN APPDELEGATE!")
    api_token.param(serverKey: appkey)
}
© www.soinside.com 2019 - 2024. All rights reserved.