我的 iOS 应用程序未显示在 Settings/Notification 中心
My iOS Application doesn't show in Settings/Notification Center
问题:我有 Iphone 6s 64GB,运行 iOS 8.3,我的应用程序没有显示在通知中心。我尝试了之前所有删除应用程序的建议,关闭 phone,然后再打开,等待 5 分钟,通过 Xcode 重新安装应用程序,再次启动应用程序,但我的应用程序仍然没有显示在通知中心。
顺便说一句,我验证了如果我的应用程序在前台 运行,我可以正确处理远程通知。
有没有人有这个问题。谢谢
这是我在 AppDelegate.swift 中的代码。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerForRemoteNotifications()
println("..... application didFinishLaunchingWithOptions()")
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
// there is a notification...do stuff...
println("dinFInishLaunchingWithOption().. calling didREceiveRemoteNotification")
self.application(application, didReceiveRemoteNotification: remoteNotification as [NSObject : AnyObject])
}
return true
}
我认为您的代码存在一个小问题
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerForRemoteNotifications()
您不需要向 registerForRemoteNotifications
提供您想注册的通知吗?
如果您查看 registerForRemoteNotifications
的文档,它指出您需要先使用 registerUserNotificationSettings:
。
// Calling this will result in either
// application:didRegisterForRemoteNotificationsWithDeviceToken: or
// application:didFailToRegisterForRemoteNotificationsWithError: to be
// called on the application delegate. Note: these callbacks will be
// made only if the application has successfully registered for user
// notifications with registerUserNotificationSettings:, or if it is
// enabled for Background App Refresh.
@availability(iOS, introduced=8.0)
func registerForRemoteNotifications()
我认为这是你应该做的:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let notificationSettings = UIUserNotificationSettings(forTypes: .Badge | .Alert | .Sound, categories: nil)
application.registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
// Rest of your setup code...
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
println("Did Register For Remote Notification")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println("Failed to Register For Remote Notifications: \(error.localizedDescription)")
}
如果您更改已注册通知的类型,此信息可能会有所帮助:
因此 iOS 在删除应用程序后将通知设置存储 24 小时。您可以尝试删除该应用程序,至少等待 24 小时,然后重新安装该应用程序。然后打开应用程序并选择“是”以允许通知,然后您可以导航到您的设置并查看通知设置。
然后,我知道无需等待 24 小时期限即可重置通知设置的唯一其他方法是擦除设备而不是从备份中恢复它。
完成测试后,您可以从备份中恢复它。
或者,您可以在测试时更改应用程序的捆绑包标识符。它应该会导致 iOS 将其视为不同的应用程序。
问题:我有 Iphone 6s 64GB,运行 iOS 8.3,我的应用程序没有显示在通知中心。我尝试了之前所有删除应用程序的建议,关闭 phone,然后再打开,等待 5 分钟,通过 Xcode 重新安装应用程序,再次启动应用程序,但我的应用程序仍然没有显示在通知中心。 顺便说一句,我验证了如果我的应用程序在前台 运行,我可以正确处理远程通知。 有没有人有这个问题。谢谢
这是我在 AppDelegate.swift 中的代码。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerForRemoteNotifications()
println("..... application didFinishLaunchingWithOptions()")
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
// there is a notification...do stuff...
println("dinFInishLaunchingWithOption().. calling didREceiveRemoteNotification")
self.application(application, didReceiveRemoteNotification: remoteNotification as [NSObject : AnyObject])
}
return true
}
我认为您的代码存在一个小问题
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerForRemoteNotifications()
您不需要向 registerForRemoteNotifications
提供您想注册的通知吗?
如果您查看 registerForRemoteNotifications
的文档,它指出您需要先使用 registerUserNotificationSettings:
。
// Calling this will result in either
// application:didRegisterForRemoteNotificationsWithDeviceToken: or
// application:didFailToRegisterForRemoteNotificationsWithError: to be
// called on the application delegate. Note: these callbacks will be
// made only if the application has successfully registered for user
// notifications with registerUserNotificationSettings:, or if it is
// enabled for Background App Refresh.
@availability(iOS, introduced=8.0)
func registerForRemoteNotifications()
我认为这是你应该做的:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let notificationSettings = UIUserNotificationSettings(forTypes: .Badge | .Alert | .Sound, categories: nil)
application.registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
// Rest of your setup code...
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
println("Did Register For Remote Notification")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println("Failed to Register For Remote Notifications: \(error.localizedDescription)")
}
如果您更改已注册通知的类型,此信息可能会有所帮助:
因此 iOS 在删除应用程序后将通知设置存储 24 小时。您可以尝试删除该应用程序,至少等待 24 小时,然后重新安装该应用程序。然后打开应用程序并选择“是”以允许通知,然后您可以导航到您的设置并查看通知设置。
然后,我知道无需等待 24 小时期限即可重置通知设置的唯一其他方法是擦除设备而不是从备份中恢复它。
完成测试后,您可以从备份中恢复它。
或者,您可以在测试时更改应用程序的捆绑包标识符。它应该会导致 iOS 将其视为不同的应用程序。