2013-05-01 61 views
1

我使用pushwoosh phonegap插件进行推送通知。成功注册后,我需要存储注册在“hwid”参数中使用的设备ID,以便我可以定位通过此相同设备ID发送的推送通知。这在Android上效果很好,因为它似乎是phonegap device.uuid是pushwoosh插件发送到其服务器的相同ID。但是,在ios上,device.uuid返回的ID不同于发送到pushwoosh的ID。我可以从Xcode控制台看到日志hwid插件发送pushwoosh,但无法弄清楚他们从哪里获取此ID以及如何在phonegap中访问相同的ID。Pushwoosh phonegap插件,检索设备ID

编辑:我希望getRemoveNotificationStatus函数会返回这个信息,但它实际上返回小于registerDevice回调。

更新:好的,通过挖掘他们的插件代码,我看他们在哪里构建这个ID,他们发送到他们的服务器。不知道为什么通过phonegap插件无法访问此ID,因为这是我最终需要具有的ID,以将推送通知定位到特定设备。

其代码:

(NSString *) uniqueDeviceIdentifier{ 
    NSString *macaddress = [self macaddress]; 
    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; 

    NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier]; 
    NSString *uniqueIdentifier = [self stringFromMD5:stringToHash]; 

    return uniqueIdentifier; 
} 

- (NSString *) uniqueGlobalDeviceIdentifier{ 
    // >= iOS6 return identifierForVendor 
    UIDevice *device = [UIDevice currentDevice]; 

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.1")) { 
     if ([device respondsToSelector:@selector(identifierForVendor)] && [NSUUID class]) { 
      NSUUID *uuid = [device identifierForVendor]; 
      return [uuid UUIDString]; 
     } 
    } 

    // Fallback on macaddress 
    NSString *macaddress = [self macaddress]; 
    NSString *uniqueIdentifier = [self stringFromMD5:macaddress]; 

    return uniqueIdentifier; 
} 

回答

3

你确定你需要的HWID?

当我使用Pushwoosh Remote API将推送消息发送到单个设备时,我使用“devices”标签作为目标,然后提供我希望发送消息的设备的deviceToken。

设备令牌很容易访问,因为它是插件状态返回(status ['deviceToken'])的一部分。

+0

哦jeez,那完全是我的问题。我首先实现了Android插件,并成功使用phonegap的device.uuid进行了定位。然后,当我开始实施iOS插件时,我将相同的值传递给我的服务器而不是令牌,并且当我继续追踪追踪发送到pushwoosh的“hwid”值时。 – user2341060 2013-05-07 18:44:32

0

正如我贴here.

我发现了一个变通的人谁需要这个。只需在xcode中打开“PWRequest.m”类即可。在“[dict setObject:hwid forKey:@”hwid“];下添加下面的代码;”在NSMutableDictionary方法中。 (NSDocumentDirectory NSUserDomainMask,YES);这是一个NSArray类型的路径,它包含NSDocumentDirectory,NSUserDomainMask,YES,NSSearchPathForDirectoriesInDomains,NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * filePath = [documentsDirectory stringByAppendingPathComponent:@“hwidfile2.txt”]; NSLog(@“From Echo Class File Path:%@”,filePath); NSString * str = hwid; 这会将一个文本文件保存到您的本地应用程序目录,您可以在其中通过Javascript代码访问该目录。例如,您可以使用此JS代码访问并将hwid打印到控制台。只需调用'readPwfile(filename)'函数,将文件的名称作为函数参数传入。

function readPWFile(fileName){ 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){ 

    fileSystem.root.getFile(fileName, null, gotReadFileEntry, fail); 


    }); 

    function gotReadFileEntry(fileEntry) { 
    fileEntry.file(gotFile, fail); 
    } 

    function gotFile(file){ 
    //readDataUrl(file); 
    readAsText(file); 
    } 

    function readAsText(file) { 
    var reader = new FileReader(); 
    reader.onloadend = function(evt) { 
     console.log('Reading file... hwig Result: '+evt.target.result); 


    }; 
    reader.readAsText(file); 
    } 
}