我的iOS应用程序未在“设置/通知中心”中显示

时间:2015-05-20 19:47:21

标签: ios apple-push-notifications

问题:Iphone 6s 64GB,运行iOS 8.3,我的应用程序没有显示在通知中心。我尝试了以前的所有建议删除应用程序,关闭手机,然后打开,等待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
    }

1 个答案:

答案 0 :(得分:1)

我相信你的代码存在一个小问题

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将其视为一个不同的应用程序。