【发布时间】:2015-06-26 06:36:33
【问题描述】:
我正在开发 APNS。 当我发送 APNS 时,提供 url 并移动 url。 APNS 成功,但是当应用程序运行时,它无法在前台收到通知。 然而,在后台,它的工作。当它在前台时 它只是在没有通知的情况下移动到 url。 你能帮帮我吗?
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [UIApplication sharedApplication].applicationState;
BOOL state_active = (state == UIApplicationStateActive);
dic_apns = [userInfo objectForKey:@"aps"];
// alert export
NSString * msg = [dic_apns objectForKey:@"alert"];
NSString * eventcode = [userInfo objectForKey:@"eventcode"];
[[NSUserDefaults standardUserDefaults] setValue :msg forKey:@"push_msg"];
[[NSUserDefaults standardUserDefaults] setValue :eventcode forKey:@"eventcode"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"APNS : msg=%@ | eventcode=%@", msg , eventcode);
[self goto_link];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
-(void) goto_link{
NSString * eventcode = [[NSUserDefaults standardUserDefaults] valueForKey:@"eventcode"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", _MAIN_URL, _PUSH_PARAM, eventcode]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
ViewController* main = (ViewController *) self.window.rootViewController;
if (!main.webview_sin )
{
NSLog(@"main.webView is nil!!!");
}
[main.webview_sin loadRequest:request];
}
【问题讨论】:
-
根据发送本地通知或显示警报检查didRecieveRemoteNotification中的应用程序状态。
标签: ios apple-push-notifications