Javascript Pushwoosh phonegap插件,检索设备ID

Javascript Pushwoosh phonegap插件,检索设备ID,javascript,ios,cordova,phonegap-plugins,Javascript,Ios,Cordova,Phonegap Plugins,我正在使用pushwoosh phonegap插件进行推送通知。成功注册后,我需要存储注册在“hwid”参数中使用的设备ID,以便我可以针对使用相同设备ID发送的推送通知。这在Android上非常有效,因为phonegap device.uuid似乎与pushwoosh插件发送到其服务器的ID相同。但是,在ios上,device.uuid返回的ID与发送到pushwoosh的ID不同。我可以从Xcode控制台日志中看到插件发送给pushwoosh的hwid,但无法确定他们从何处获取该ID以及如何

我正在使用pushwoosh phonegap插件进行推送通知。成功注册后,我需要存储注册在“hwid”参数中使用的设备ID,以便我可以针对使用相同设备ID发送的推送通知。这在Android上非常有效,因为phonegap device.uuid似乎与pushwoosh插件发送到其服务器的ID相同。但是,在ios上,device.uuid返回的ID与发送到pushwoosh的ID不同。我可以从Xcode控制台日志中看到插件发送给pushwoosh的hwid,但无法确定他们从何处获取该ID以及如何在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;
}

您确定需要hwid吗

当我使用Pushwoosh远程API将推送消息发送到各个设备时,我使用“devices”标记作为目标,然后只提供我希望发送消息的设备的deviceToken

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

如我所述

我为任何需要这个的人找到了工作。只需在xcode中打开类“PWRequest.m”。在NSMutableDictionary方法的“[dict setObject:hwid forKey:@“hwid”];”下添加下面的代码

NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory NSUserDomainMask,是); NSString*documentsDirectory=[paths objectAtIndex:0]; NSString*文件路径=[DocumentsDirectoryStringByAppendingPathComponent:@“hwidfile2.txt”]; NSLog(@“来自Echo类文件路径:%@”,文件路径); 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);
   }
}

哦,天哪,那完全是我的问题。我首先实现了Android插件,并成功地将phonegap的device.uuid作为目标。然后,当我开始实现iOS插件时,我将相同的值传递给我的服务器,而不是令牌,并且当我开始大惊小怪地追踪发送给pushwoosh的“hwid”值时。