我有个奇怪的问题。
注册通知的代码如下:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// PUSH NOTIFICATION
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()
以及处理通知:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
let notification = UILocalNotification()
notification.soundName = UILocalNotificationDefaultSoundName
notification.alertBody = "TEST"
application.presentLocalNotificationNow(notification)
当我在xcode中测试这个简单的代码时(使用设备,而不是模拟器),没有问题。但是当我在没有xcode的情况下测试它时(就在我的手机上),本地通知不会出现:没有声音,没有警报,没有徽章,什么都没有。
应用程序在后台运行时出现此问题。
发送的APN是静默通知。
有办法修一下吗?
编辑
我通过将静默APN的优先级降低到5来解决这个问题。
最佳答案
当通过xcode安装时,通知将使用开发(gateway.sandbox.push.apple.com)url。将其导出为ipa(即席)并手动安装需要从production url gateway.push.apple.com发送通知(包括生产密钥)。因此,您必须创建这两个键,然后您可以在使用xcode时使用开发url发送通知,在从导出的ipa安装时使用产品发送通知。