gpt4 book ai didi

ios - 工作灯 : get device token

转载 作者:行者123 更新时间:2023-12-01 16:39:23 24 4
gpt4 key购买 nike

worklight 是否可以返回 Android/iPhone/BB 的设备 token ,如果可以,如何返回?

更具体地说,我不是在寻找“设备 ID”,而是在寻找 native 设备 token 。

Worklight 可以返回“设备 ID”,但这与设备 token 不同。例如 Worklight: How to get current device ID for Push subscription说明如何使用调用获取“设备 ID”

WL.Client.getUserInfo("wl_deviceNoProvisioningRealm", "userId");

不幸的是,这会返回与设备 token 不同的东西。当像这样使用 native iPhone 调用并将其与 WL deviceid 进行比较时,很明显它们是不同的。

- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

NSMutableDictionary *results = [NSMutableDictionary dictionary];
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[results setValue:token forKey:@"deviceToken"];

#if !TARGET_IPHONE_SIMULATOR
[results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] forKey:@"appName"];
[results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"appVersion"];


NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

// Set the defaults to disabled unless we find otherwise...
NSString *pushBadge = @"disabled";
NSString *pushAlert = @"disabled";
NSString *pushSound = @"disabled";

if(rntypes & UIRemoteNotificationTypeBadge){
pushBadge = @"enabled";
}
if(rntypes & UIRemoteNotificationTypeAlert) {
pushAlert = @"enabled";
}
if(rntypes & UIRemoteNotificationTypeSound) {
pushSound = @"enabled";
}

[results setValue:pushBadge forKey:@"pushBadge"];
[results setValue:pushAlert forKey:@"pushAlert"];
[results setValue:pushSound forKey:@"pushSound"];

// Get the users Device Model, Display Name, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
[results setValue:dev.name forKey:@"deviceName"];
[results setValue:dev.model forKey:@"deviceModel"];
[results setValue:dev.systemVersion forKey:@"deviceSystemVersion"];

[self successWithMessage:[NSString stringWithFormat:@"%@", token]];

#else
[self successWithMessage:[NSString stringWithFormat:@"%@", @"simulator generated"]];
#endif

}

此外,Worklight 之外的第三方通知平台需要本地设备 token ,因此使用 Worklight 消息传递系统是不可行的。

最佳答案

您是正确的 APNs 设备 token 和 Worklight deviceId 是两个不同的东西。如果您需要 APNs 设备 token 来使用某些 3rd 方通知平台,您可以覆盖应用程序委托(delegate)中的 didRegisterForRemoteNotificationsWithDeviceToken 方法,从而在设备 token 从 APNs 到达时获得对设备 token 的完全控制权

关于ios - 工作灯 : get device token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25750936/

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