gpt4 book ai didi

ios - 推送套件未收到pushCredentials token

转载 作者:行者123 更新时间:2023-11-29 05:55:13 24 4
gpt4 key购买 nike

我是集成 Push Kit 的新手,因此无法接收 PushCredentials token ,请建议我解决方案。

下面是我的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// For debugging
//OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)

//Enable all notification type.
let notificationSettings = UIUserNotificationSettings(types: [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound] , categories: nil)

//register the notification settings
application.registerUserNotificationSettings(notificationSettings)


return true
}

extension AppDelegate {

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {

//register for voip notifications
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.desiredPushTypes = Set([PKPushType.voIP])
voipRegistry.delegate = self;

print("didRegisterUserNotificationSettings")
}
}


extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType type: PKPushType) {
print("voip token: \(pushCredentials.token)")

}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {

let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary<String, String>
let message = payloadDict?["alert"]

//present a local notifcation to visually see when we are recieving a VoIP Notification
if UIApplication.shared.applicationState == UIApplicationState.background {

let localNotification = UILocalNotification();
localNotification.alertBody = message
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;

UIApplication.shared.presentLocalNotificationNow(localNotification);
}

else {
print(message)
// dispatch_async(DispatchQueue.main, { () -> Void in
//
// let alert = UIAlertView(title: "VoIP Notification", message: message, delegate: nil, cancelButtonTitle: "Ok");
// alert.show()
// })
}

NSLog("incoming voip notfication: \(payload.dictionaryPayload)")
}

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
NSLog("token invalidated")
}
}

extension UIApplicationState {

//help to output a string instead of an enum number
var stringValue : String {
get {
switch(self) {
case .active:
return "Active"
case .inactive:
return "Inactive"
case .background:
return "Background"
}
}
}
}

我是否遗漏了一些东西,请提出建议。

最佳答案

      func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType type: PKPushType) {
let deviceTokenString = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
print("deviceTokenString \(deviceTokenString)")

}

关于ios - 推送套件未收到pushCredentials token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55239465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com