iOS 12 推送通知在以下版本中不起作用,在 iOS 12 中未收到推送通知

标签 ios swift apple-push-notifications ios12

对于 iOS 12 推送通知不工作并且在以下版本中工作

我的应用程序在 Appstore 中。推送通知在 iOS 11 中运行良好,但在 iOS 12 中不起作用。我没有收到任何 iOS 12 设备的推送通知。我已经检查了服务器中的设备 token 和证书。全部正确。我还检查了设置应用程序中的通知属性。一切都很好。但是我没有收到任何通知。

这是我用于推送通知的代码。

你能告诉我会是什么问题吗?如何解决这个问题?

func registerForPushNotifications() {

    if #available(iOS 10.0, *){

        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            if (granted)
            {
                UIApplication.shared.registerForRemoteNotifications()
            }
            else{
                //Do stuff if unsuccessful...
                 UIApplication.shared.registerForRemoteNotifications()
            }
            // Enable or disable features based on authorization.
        }
    }
    else
    {

        let types: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
        let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: types, categories: nil )
        UIApplication.shared.registerUserNotificationSettings( settings )
        UIApplication.shared.registerForRemoteNotifications()

    }

}



@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let userInfo = response.notification.request.content.userInfo as NSDictionary

    print(userInfo)


}

最佳答案

当我的应用程序在“调试”中运行时,我遇到了同样的问题,
我在“发布”中运行应用程序并且通知工作正常

关于iOS 12 推送通知在以下版本中不起作用,在 iOS 12 中未收到推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52496807/

相关文章:

ios - 临时 AIR 应用程序安装,没有 UDID

ios - ScrollView 中图像的自动布局

Swift - UISwitch 作为两个值之间的选择器?

swift - No recognize of StorageMetadata//类型 'StorageMetadata'的值没有成员 'downloadURL'

iOS:当应用程序处于后台时防止显示特定通知

iphone - APNs 如何定位要向其发送通知的设备?

ios - Apple 远程通知 - 处理 token 更改

ios - 如何将自定义对象加载和保存到 iOS 和 OSX?

ios - 仅将 pod 的子集用于子目标

ios - 将 Assets 视频发送到网络服务 - iOS