Pushwoosh phonegap插件,检索设备ID

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

编辑:我希望getRemoveNotificationStatus函数将返回此信息,但实际上返回less于registerDevicecallback。

更新:好的,通过挖掘他们的插件代码,我看他们在哪里构build这个ID,他们发送到他们的服务器。 不知道为什么这个ID不能通过phonegap插件访问,因为这是我最终需要具有的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; } 

你确定你需要这个hwid吗?

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

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

正如我在这里发布的。

我find了解决这个问题的方法。 只需在xcode中打开“PWRequest.m”类即可。 在“[dict setObject:hwid forKey:@”hwid“]下添加下面的代码;” 在NSMutableDictionary方法。

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * filePath = [documentsDirectory stringByAppendingPathComponent:@“hwidfile2.txt”]; NSLog(@“从回声类文件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); } }