|
/

IOS 推送初始化后,后台预估人数为0

S沙城
发布于 4 年前
4260来自重庆
消息推送 U-Push
API调用

没有执行下面的代码取到token

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
debugPrint("============deviceToken=====\(deviceToken)")
}


其余代码如下

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UMCommonLogManager.setUp()
UMConfigure.setLogEnabled(true)
UMConfigure.initWithAppkey("xxx", channel: "App Store")
let entity = UMessageRegisterEntity()
entity.types = Int(UMessageAuthorizationOptions.badge.rawValue | UMessageAuthorizationOptions.alert.rawValue | UMessageAuthorizationOptions.sound.rawValue);
UNUserNotificationCenter.current().delegate = self

UMessage.registerForRemoteNotifications(launchOptions: launchOptions,entity: entity){ s , err in

debugPrint(s) //这里返回为true

}
return true
}

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

let userInfo = response.notification.request.content.userInfo;
if(response.notification.request.trigger?.isKind(of:UNPushNotificationTrigger.self ) == true) {
UMessage.didReceiveRemoteNotification(userInfo)
}else{
//应用处于后台时的本地推送接受
}

}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo;
if(notification.request.trigger?.isKind(of:UNPushNotificationTrigger.self) == true){
UMessage.setAutoAlert(false)
//必须加这句代码
UMessage.didReceiveRemoteNotification(userInfo)


}else{
//应用处于前台时的本地推送接受
}
}

4个回答
 
4 年前
来自上海

楼主你好,根据你的截图你的方式是对的,你排查一下消息推送的证书是否开通推送功能。

 
4 年前
来自天津

你好,你是生产模式还是开发模式

Loading ...
登录社区,分享你的经验