gpt4 book ai didi

javascript - 如何将数据从appdelegate传递到jquerymobile中的index.html

转载 作者:行者123 更新时间:2023-11-28 08:38:39 24 4
gpt4 key购买 nike

这是appdelegate.m,用于获取设备 token ,与如何在index.js中的phonegap中写入相同的内容

Appdelegate.m

(BOOL) application: (UIApplication * ) application didFinishLaunchingWithOptions: (NSDictionary * ) launchOptions {
CGRect screenBounds = [
[UIScreen mainScreen] bounds
];
[
[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)
];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0; - (void) application: (UIApplication * ) application didReceiveRemoteNotification: (NSDictionary * ) userInfo {} - (void) application: (UIApplication * ) application didRegisterForRemoteNotificationsWithDeviceToken: (NSData * ) deviceToken {
NSString * devtoken = [NSString stringWithFormat: @"%@", deviceToken];
NSLog(@"the devicetoken is %@", devtoken);
NSRange r1 = [devtoken rangeOfString: @"<"];
NSRange r2 = [devtoken rangeOfString: @">"];
NSRange rSub = NSMakeRange(r1.location + r1.length, r2.location - r1.location - r1.length);
NSString * sub = [devtoken substringWithRange: rSub];
NSLog(@"%@", sub);
NSString * newString = [sub stringByReplacingOccurrencesOfString: @" "
withString: @""
];
UIAlertView * message = [
[UIAlertView alloc] initWithTitle: @"Device Token!"
message: newString
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil
];
[message show];
NSLog(@"%@", newString);
} - (void) application: (UIApplication * ) application didFailToRegisterForRemoteNotificationsWithError: (NSError * ) error {
NSLog(@"the reason for fail to register the remote notifications is %@", error);
}

最佳答案

您可以在js文件中获取设备 token ,例如

- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

DLog(@"didRegisterForRemoteNotificationsWithDeviceToken:%@", deviceToken);

NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];

NSMutableDictionary *results = [PushNotification getRemoteNotificationStatus];
[results setValue:token forKey:@"deviceToken"];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:results];
[self writeJavascript:[pluginResult toSuccessCallbackString:[self.callbackIds valueForKey:@"registerDevice"]]];
}

在上面的代码中,pluginResult将被传递,同样我们可以在回调函数中获取deviceToken。

请从下面的链接找到推送通知插件

https://github.com/phonegap-build/PushPlugin

https://github.com/mgcrea/cordova-push-notification

关于javascript - 如何将数据从appdelegate传递到jquerymobile中的index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com