iOS 12推送通知无法正常工作,而在以下版本中可以正常工作,在iOS 12中无法接收推送通知。

9

iOS 12推送通知无法正常工作,而在以下版本中可以正常工作。

我的应用已经发布在Appstore上。在iOS 11上,推送通知可以正常工作,但是在iOS 12上无法正常接收到推送通知。我已检查了服务器上的设备令牌和证书,这些都是正确的。我也检查了设置应用中的通知属性,一切都正常。但我没有收到任何通知。

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

请问您能否建议我可能存在的问题以及如何解决它?

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)


}

请参考以下链接以获取帮助:https://dev59.com/JFkS5IYBdhLWcg3w25sM#39383027 - Anbu.Karthik
@Anbu.karthik 推送通知在iOS 12以下的版本中,无论是后台还是前台都可以正常工作,问题仅出现在iOS 12上。 - Sandeep Baddula
给我时间,我会检查并更新您。 - Anbu.Karthik
你解决了你的问题吗? - Abdullah Umer
@SandeepBaddula 你有找到任何解决方案吗? - US-1234
@Sandeep Baddula,你解决了这个问题吗? - bibscy
1个回答

3

当我的应用程序在“debug”模式下运行时,我遇到了同样的问题,但是当我将应用程序在“release”模式下运行时,通知就能正常工作。


嗨,对我来说推送通知也没有起作用。如果我们从Xcode中构建项目,则不起作用;如果我从命令提示符中构建项目,则通知会出现。我在Ionic框架版本3中使用Firebase推送通知。我升级了我的Mac iOS版本到12和Xcode版本到10,然后通知停止工作了。有人可以帮忙解决这个问题吗? - Midhunsai

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接