2014-02-17 58 views
1

我在其中一个应用程序中使用通知,当应用程序处于活动状态时收到通知,我处理数据并且一切正常,但应用程序处于未处理状态时我没有收到任何通知背景或遇难。有什么问题可以帮助我吗?当应用程序在后台时未收到UINotification ios

谢谢!

这是我做的,到目前为止

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    tokenstring = [[NSString alloc] initWithFormat:@"%@",deviceToken]; 

    tokenstring = [tokenstring stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
    tokenstring = [[NSString alloc]initWithFormat:@"%@",[tokenstring stringByReplacingOccurrencesOfString:@" " withString:@""]]; 
    NSLog(@"TokeinID:>> %@",tokenstring); 


} 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    NSLog(@"didReceiveRemoteNotification: %@",userInfo); 
    AudioServicesPlaySystemSound(1002); 

    //Some code or logic 
} 
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"didFailToRegisterForRemoteNotificationsWithError: %@",err.description); 



} 
+0

什么有效载荷时,设备接收推送通知你好吗? –

+0

如果您的应用程序在后台,并且通知已到,它会在通知中心显示,当用户点击该通知时,会调用didReceiveRemoteNotification方法。 –

+0

嗨阿曼有问题的有效载荷,谢谢大家 – user3295961

回答

3

当您收到远程通知,当你的应用程序是在前台-application:didReceiveRemoteNotification:只调用。如果您的应用程序处于后台或已终止,则操作系统可能会显示警报或播放声音(取决于通知中的aps字典),但不会调用委托方法。

如果后台收到的远程通知与该通知的操作按钮一起启动,则只会传递给您的应用程序,然后您需要查看-application:didFinishLaunchingWithOptions:上的启动选项字典以查看通知的内容。

如果你正在寻找新的内容读取/远程通知的背景支持,iOS7,检查Will iOS launch my app into the background if it was force-quit by the user?并看看是否有帮助,因为有非常特殊的情况下,这些功能工作。

1

小代码..

当应用程序没有运行

(BOOL)应用:(UIApplication的*)应用 didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions

被称为..

其中u需要检查推送通知

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
if (notification) { 
    NSLog(@"app recieved notification from remote%@",notification); 
    [self application:application didReceiveRemoteNotification:(NSDictionary*)notification]; 
}else{ 
} 
相关问题