如何检查用户是否以及何时对此视图执行操作?
我想这样做:
if notificationviewclosed{
dosomething
}
然而,我无法找到一个合适的方法来检查这个。这是我的代码:
func SetupPushNotifications(){
// Register for Push Notitications
var userNotificationTypes:UIUserNotificationType = (UIUserNotificationType.Alert |
UIUserNotificationType.Badge |
UIUserNotificationType.Sound)
if UIApplication.sharedApplication().respondsToSelector("isRegisteredForRemoteNotifications"){ //this should be done with getobjc method
// iOS 8 Notifications
var settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
}else{
// iOS < 8 Notifications
UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
}
}
答案 0 :(得分:3)
您可以通过在AppDelegate中实现以下两种方法来处理用户对提示的响应。
适用于iOS8:
func application(_ application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)
For&lt; iOS8上:强>
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
在此方法中,您可以通过调用以下内容并检查值
来检查用户是否已授予权限application.enabledRemoteNotificationTypes()