2014-09-09 5 views
2

워크로드로 Android/iPhone/BB의 기기 토큰을 반환 할 수 있습니까?Worklight : 기기 토큰 받기

더 구체적으로 말하면, "장치 ID"가 아니라 기본 장치 토큰을 찾고 있습니다.

Worklight는 "장치 ID"를 반환 할 수 있지만 장치 토큰과 다릅니다. 예를 들어 Worklight: How to get current device ID for Push subscription은 전화를 사용하여 "장치 ID"를 얻는 방법을 명시합니다.

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

불행히도 이것은 기기 토큰과 다른 것을 반환합니다. 네이티브 아이폰 호출을 사용하고 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 

} 

또한, 네이티브 장치 토큰 작업등의 외부 등이다 worklights 메시징 시스템을 사용하는 것은 가능하지 않다 타사 통지 플랫폼이 필요하다.

답변

0

올바른 APN 장치 토큰 및 Worklight deviceId는 두 가지가 있습니다. 일부 타사 알림 플랫폼을 사용하기 위해 APN 장치 토큰이 필요한 경우 응용 프로그램 대리인의 didRegisterForRemoteNotificationsWithDeviceToken 메서드를 재정 의하여 APN에서 장치 토큰을 완전히 제어 할 수 있습니다.

+0

질문은 다음과 같은 이유로 장치 토큰을 반환 할 수 있습니다. 안드로이드, 아이폰, 그리고 BB와 만약 그렇다면 어떻게? 워크 라이트는 장치 토큰을 반환 할 수 없으며 플랫폼마다 별도로 구현되어야 함을 의미합니다. – Wontonimo

+1

WL의 푸시 알림 엔진을 사용하는 경우 액세스 토큰을 얻는 논리와 WL 서버에보고하는 작업이 WL 런타임 내에 캡슐화되어 있기 때문에 액세스 토큰에 대해 걱정할 필요가 없습니다. 따라서 WL은 장치 토큰에 액세스하기위한 API를 제공하지 않습니다. WL의 푸시 알림 엔진을 사용하지 않는 경우 플랫폼 당 액세스 토큰을 수동으로 가져와야합니다. – Anton