2

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

更具体地说,我不是在寻找“设备 ID”,而是在寻找本机设备令牌。

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

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

不幸的是,这会返回与设备令牌不同的东西。当像这样使用本机 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 之外的第三方通知平台需要本地设备令牌,因此使用 Worklight 消息传递系统是不可行的。

4

1 回答 1

0

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

于 2014-09-10T07:36:12.807 回答