【发布时间】:2014-03-22 09:17:43
【问题描述】:
如何在 Objective C 中将数据从一个类发送到另一个类?或者也许我如何将字符串存储到全局变量中?我主要是一名 JavaScript 开发人员,但被困在这方面。我不记得有足够的 Obj C 来编写自己的纸板箱代码。
我向我的 PhoneGap 应用程序添加了推送通知,但我无法将令牌字符串传递给 web 视图。我正在使用 Meteor,所以我在 web 视图中调用 Session.set('token', 'abc'); 来存储它。当我尝试从didRegisterForRemoteNotificationsWithDeviceToken 注入它时,它会在 html 页面完成加载之前触发。任何帮助都非常感谢。
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
// would like to do:
globalToken = deviceToken;
}
.
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
// inject token
NSString* jsString = [NSString stringWithFormat:@"setTimeout(function(){ Session.set('push:ios', '%@'); }, 7000);", globalToken];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
return [super webViewDidFinishLoad:theWebView];
【问题讨论】:
标签: ios objective-c cordova