My appには2種類の初期状態があります。ダッシュボード&他のものが含まれてログインした後iOS 10でプッシュ通知を表示する際の問題Swift 3
- ログイン
- 。その
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let userDataExist = CommonUserFunction.isUserDataExist() as Bool if userDataExist == true { let homeViewController = self.window?.rootViewController?.storyboard?.instantiateViewController(withIdentifier: "HomeView") as? HomeViewController let navigationController = UINavigationController() navigationController.viewControllers = [homeViewController!] self.window!.rootViewController = navigationController } else{ let loginController = self.window?.rootViewController?.storyboard?.instantiateViewController(withIdentifier: "LoginView") as? LoginController let navigationController = UINavigationController() navigationController.viewControllers = [loginController!] self.window!.rootViewController = navigationController } self.window?.makeKeyAndVisible() return true }
ようAppdelegateからビューを切り替えたとき、私はプッシュ通知を処理しなければならないとき、私は問題に直面しています細かい作業
マイアプリ。私は私が通知トレイからの通知をタップするとアプリが前景または背景であるのに対し、これら2つの方法が発射さ
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) {
print("Handle push from foreground")
// custom code to handle push while app is in the foreground
print(notification.request.content.userInfo)
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
// custom code to handle push while app is in the foreground
print(response.notification.request.content.userInfo)
}
これらの方法でのiOS 10にプッシュ通知を受信しました。通知をタップしたら、私は詳細ページを表示する必要があります。私は私がdidFinishLaunchingWithOptionsメソッド
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
let pushResponse = response.notification.request.content.userInfo as NSDictionary
let rtype = pushResponse.object(forKey: "rtype") as? String
let rid = pushResponse.object(forKey: "rid") as? String
if rtype != nil {
if rtype == "5" {
if rid != nil {
let noticeDetailsViewController = self.storyboard?.instantiateViewController(withIdentifier: "NoticeDetailsView") as? NoticeDetailsController
noticeDetailsViewController!.id = rtype!
noticeDetailsViewController?.fromPush = true
let navigationController = UINavigationController()
navigationController.viewControllers = [noticeDetailsViewController!]
self.window!.rootViewController = navigationController
}
}
}
}
私はそのアプリのクラッシュを行うたびに前にしたもののような詳細ページを設定しようとしました。これを克服する方法。助けてください。前もって感謝します。
あなたのアプリがクラッシュする –
userNotificationCenterメソッドの詳細ビューをrootviewControllerとして設定すると、 –
あなたのクラッシュログは何ですか? 見せてもらえますか ? –