我正在尝试使用 Urban Airship 和 phonegap 进行自定义推送以重定向视图。基本上我想发送一个自定义数据推送,如下所示:
"aps": {"alert": "Hello!", "extra":{"targetURL":"www.google.com"}}
并将应用程序的视图重定向到 targetURL。
现在我的通知处理程序是:
-(void)handleNotification:(NSDictionary *)notification withCustomPayload:(NSDictionary *)customData{
UALOG(@"Received an alert with a custom payload");
NSString *URL = [customData objectForKey:@"targetURL"];
//UIWebView *view = [PhoneGapDelegate
AppDelegate *mainDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[mainDelegate redirectTo:URL];
}
重定向函数如下所示,位于 AppDelegate 中:
- (void) redirectTo:(NSString *){
URL{NSLog(@"In redirect in cocoa");
[[self webView] stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"goTo('%@');", URL]];
}
这段代码确实调用了我用来重绘视图的 javascript 函数,但是一旦我发送通知,我就无法让它重绘。以这种方式或其他更有效的方式进行视图重绘的任何帮助都会有所帮助。