【发布时间】:2016-06-15 12:42:11
【问题描述】:
如果应用程序终止后从通知正文启动应用程序,我正在尝试打开弹出框。我想从AppDelegate 开始。我正在使用LocalNotifications。如果我使用操作按钮,我知道如何打开特定视图,但如果单击通知正文,我不知道如何打开某些内容。
编辑:我的解决方案仅在应用未终止时才有效。
Edit2:这样做是否正确?:
为简单起见,我试图在代码中打开viewController,但实际上我需要警报消息,因为我正在使用JSSAlertView
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
if let TappedNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? NSDictionary {
print("The notification is \(TappedNotification)")
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
}
}
return true
}
我试过这个来检测应用程序处于哪个状态,但如果应用程序被终止并从通知中打开,我无法测试它:
if application.applicationState == UIApplicationState.Active {
print("App already open")
} else {
print("App opened from Notification")
}
我尝试将其添加到else{,但它没有打开特定视图:
让 mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
如果单击通知正文,我想要与 Twitter 或 Instagram 相同的效果,它会将您重定向到帖子。但就我而言,我只想要 popover(modal)。
【问题讨论】:
标签: swift uiviewcontroller appdelegate