【发布时间】:2016-06-13 18:57:48
【问题描述】:
我有一个奇怪的问题。
注册通知的代码如下:
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?span>
-
我的意思是没有调试。我只是在手机上运行该应用程序来测试它。
标签: ios swift apple-push-notifications