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服务请求失败。

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

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

最佳答案

您的问题与您想要的问题有所不同。
一种解决方案是在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)
}

关于ios - iOS 10 UNNotificationAction,可以从后台模式切换到前台模式吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42819235/

10-10 04:03