我正在使用pushwoosh向我的ios移动应用程序发送推送通知。我希望允许用户在应用程序中禁用通知。我遇到的问题是,pushwoosh为ios使用的设备id与用于android的设备id不同。设备id由插件使用本机代码创建。它使用硬件mac地址并应用md5算法创建phonegap称之为“hwid”(硬件id)的“唯一”id。我已经找到了本机的目标c类,但是我不知道如何从Javascript访问变量"hwid“。
我已经阅读了phonegap 文档,并创建了一个插件,允许我访问本地ios类。我的问题是,我不知道目标c,因此无法知道如何将变量返回给回调。
pushwoosh需要设备id才能注销设备,如下所示:
{
"request":{
"application":"APPLICATION_CODE",
"hwid": "hardware device id"
}
}我看过这的帖子,这对我想要完成的工作没有任何帮助。但是,它确实显示了创建唯一id的本机代码。
我还找到了将hwid打印到控制台的类。如果我能从js代码中找到一种访问下面"hwid“的方法,那么我就都设置好了。
#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有人能给我指明正确的方向吗?谢谢。
发布于 2013-09-24 18:00:06
我为任何需要这个的人找到了一个解决办法。只需打开xcode中的类"PWRequest.m“即可。将下面的代码添加到NSMutableDictionary方法中的"dict :hwid:@“hwid”;“下面。
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;这将保存一个文本文件到您的本地应用程序目录,您可以在其中访问您的Javascript代码。例如,您可以使用此JS代码访问hwid并将其打印到控制台。只需调用‘readPwfile(文件名)’函数,将文件名作为函数参数传递。
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);
}
}发布于 2013-09-24 13:33:46
我们刚刚为unregisterDevice Phonegap添加了iOS方法。PushNotification.prototype.unregisterDevice =函数(成功,失败){cordova.exec(成功,失败,"PushNotification","unregisterDevice",[]);};
它以前只适用于安卓系统,现在也可以在iOS上使用了。有关Phonegap3.0,请参阅最新的Pushwoosh插件回购:https://github.com/shaders/pushwoosh-phonegap-3.0-plugin
有关旧版本的Phonegap版本<= 2.9,请参阅遗留的Pushwoosh插件:https://github.com/shaders/phonegap-cordova-push-notifications/tree/master/iOS
希望能帮上忙!
https://stackoverflow.com/questions/18948810
复制相似问题