Pergunta

I'm using pushwoosh to send push notifications to my ios mobile app. I want to allow users to disable notifications from within the app. The problem I'm having is that the pushwoosh api uses a different device id for ios than it does for android. The device id is created by the plugin using native code. It uses the hardware mac address and applies the md5 algorithm to create a "unique" id that phonegap is calling "hwid"(hardware id). I've found the native, objective c class that does this but I don't know how to access the variable, "hwid", from Javascript.

I've read through the phonegap documentation and have created a plugin that allows me to access native ios classes. My problem is that I don't know objective c and therefore cannot figure out how to return the variable to the callback.

The pushwoosh api requires the device id in order to unregister a device as you can see here:

{
   "request":{
      "application":"APPLICATION_CODE",
      "hwid": "hardware device id"
   }
}

I have seen this post and it is not helpful for what I'm trying to accomplish. However, it does show the native code that creates the unique id.

I also found this class that prints the hwid to the console. If I could find a way to access the "hwid" below from my js code I would be all set.

#import "PWRequest.h"

@implementation PWRequest
@synthesize appId, hwid;

- (NSString *) methodName {
return @"";
}

//Please note that all values will be processed as strings
- (NSDictionary *) requestDictionary {
        return nil;
}

- (NSMutableDictionary *) baseDictionary {
        NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:appId forKey:@"application"];
    [dict setObject:hwid forKey:@"hwid"];
        NSLog(@"hwid: %@", hwid);

    return [dict autorelease];
}

- (void) parseResponse: (NSDictionary *) response {
}

- (void) dealloc {
    self.appId = nil;
    self.hwid = nil;

    [super dealloc];
}

@end

Can someone point me in the right direction? Thanks.

Foi útil?

Solução 2

I found a work-around for anyone who needs this. Just open up the class "PWRequest.m" in xcode. Add the code below just under "[dict setObject:hwid forKey:@"hwid"];" in the NSMutableDictionary method.

NSArray *paths = 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;

This will save a text file to your local app directory in which you can access from your Javascript code. For example, you can use this JS code to access and print the hwid to the console. Just call the 'readPwfile(filename)' function, passing in the name of your file as the function argument.

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);
    }
 }

Outras dicas

We have just added unregisterDevice method for iOS Phonegap Javascript. PushNotification.prototype.unregisterDevice = function(success, fail) { cordova.exec(success, fail, "PushNotification", "unregisterDevice", []); };

It used to work only for Android, now it is available on iOS as well. For Phonegap 3.0 please see the newest Pushwoosh plugin repo: https://github.com/shaders/pushwoosh-phonegap-3.0-plugin

For older Phonegap versions <= 2.9 please see legacy Pushwoosh Phonegap plugin: https://github.com/shaders/phonegap-cordova-push-notifications/tree/master/iOS

I hope it helps!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top