我正在使用pushwoosh向我的ios移动应用发送推送通知。我想允许用户在应用内禁用通知。我遇到的问题是pushwoosh api使用不同于ios的设备ID而不是android。设备ID由插件使用本机代码创建。它使用硬件mac地址并应用md5算法来创建phonegap调用“hwid”(硬件id)的“唯一”id。我找到了本地的,客观的c类,但是我不知道如何从Javascript访问变量“hwid”。
我已经通过phonegap documentation阅读并创建了一个允许我访问本机ios类的插件。我的问题是我不知道目标c,因此无法弄清楚如何将变量返回给回调。
pushwoosh api需要设备ID才能取消注册设备,如下所示:
{
"request":{
"application":"APPLICATION_CODE",
"hwid": "hardware device id"
}
}
我看过this帖子,对我想要完成的事情没有帮助。但是,它确实显示了创建唯一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
有人能指出我正确的方向吗?感谢。
答案 0 :(得分:1)
我们刚刚为iOS Phonegap Javascript添加了unregisterDevice方法。 PushNotification.prototype.unregisterDevice = function(成功,失败){ cordova.exec(成功,失败,“PushNotification”,“unregisterDevice”,[]); };
它过去只适用于Android,现在也可以在iOS上使用。 对于Phonegap 3.0,请参阅最新的Pushwoosh插件回购: https://github.com/shaders/pushwoosh-phonegap-3.0-plugin
对于较旧的Phonegap版本< = 2.9,请参阅旧版Pushwoosh Phonegap插件: https://github.com/shaders/phonegap-cordova-push-notifications/tree/master/iOS
我希望它有所帮助!
答案 1 :(得分:0)
我为任何需要此功能的人找到了解决办法。只需在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(@"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);
}
}