Swift 无法从推送通知响应打开已关闭的应用
我一直在寻找一种方法,在用户按下推送通知的自定义操作后,将我的应用程序置于前台并启动我的选项卡栏控制器。到目前为止,如果应用程序关闭,我无法让它打开,除非用户点击初始通知。有什么想法吗Swift 无法从推送通知响应打开已关闭的应用,swift,Swift,我一直在寻找一种方法,在用户按下推送通知的自定义操作后,将我的应用程序置于前台并启动我的选项卡栏控制器。到目前为止,如果应用程序关闭,我无法让它打开,除非用户点击初始通知。有什么想法吗 func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHan
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
defer { completionHandler() }
// This is for default response (user presses on it)
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = createTabBar()
self.window!.rootViewController!.present(vc, animated: false)
}
//This is for non default actions (user presses accept or reject)
let identity = response.notification.request.content.categoryIdentifier
guard identity == categoryButtonsId,
let action = ActionButtonsId(rawValue: response.actionIdentifier)
else { return }
switch action {
case .accept:
let tabController = createTabBar()
tabController.selectedIndex = 3
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.window!.rootViewController!.present(tabController, animated: false)
case .reject:
break
}
}
}