iOS 10未通知操作,可以从后台模式移动到前台模式吗?
UINotificationAction的定义如下iOS 10未通知操作,可以从后台模式移动到前台模式吗?,ios,swift,push-notification,ios10,Ios,Swift,Push Notification,Ios10,UINotificationAction的定义如下 let customAction = UNNotificationAction(identifier: "customCategory.Action", title: "Do something", options: []) 单击后,将发出web服务请求,以使用UNUserNotificationCenterDelegate方法获取数据,如下所示 func userNotificationCenter(_ center: UNUserNoti
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服务请求将失败
根据要求,在此故障场景中,应显示登录屏幕
是否可以将应用程序从后台模式移动到前台以显示登录屏幕?您的问题与您想要的不同。。为了有这样的。。 1解决方案是在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)
}
您不能让应用自行进入前台。尽管您可以更改根控制器,并在需要时显示登录屏幕!显示登录屏幕,只有当用户再次启动应用程序时才会出现右键?