【问题标题】:iOS 10 UNNotificationAction, can move from background to foreground mode?iOS 10 UNNotificationAction,可以从后台切换到前台模式吗?
【发布时间】:2017-08-06 18:01:46
【问题描述】:

UINotificationAction 定义如下

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

点击后,这将使用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】:

您的问题与您想要的不同.. 为了有这样的.. 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)
}

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 2017-03-03
    • 2015-05-31
    • 2013-03-24
    • 1970-01-01
    • 2016-03-15
    相关资源
    最近更新 更多