2013-05-01 56 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); 
    } 
}