2013-04-27 78 views
0

我在3个地方为您在AppDelegate类新的消息接收远程推送消息,在didFinishLaunchingWithOptions:(NSDictionary *)launchOptions我在哪里需要使用代码的应用程序

if (launchOptions != nil) 
    { 
     NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     if (dictionary != nil) 
     { 
      //NSLog(@"Launched from push notification: %@", dictionary); 
      //notification pending ... so pull from server the new message 
      [self addMessageFromRemoteNotification:dictionary updateUI:YES]; 
     } 
    } 

didReceiveRemoteNotification:(NSDictionary*)userInfo使用代码:

// notification pending ... so pull from server the new message 
[self addMessageFromRemoteNotification:userInfo updateUI:YES]; 

- (void)applicationDidBecomeActive:(UIApplication *)application使用代码

if(application.applicationIconBadgeNumber>0) 
    { 

     application.applicationIconBadgeNumber = 0; 
     // notification pending ... so pull from server the new message 
     [self openMessageViewForNewMessage]; 


    } 

不过,我仍请注意,有些情况下我的应用程序仍然不会“捕捉”通知,也就是说,它仍不知道它会收到通知。我有消息吗?或者我应该一直检查“我的服务器”是否有新的消息,因为应用程序可能并不是所有的时间都会通知iOS有新的通知。

回答

1

快速浏览......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

在此指定您希望您的应用程序收到什么样的通知。例如,如果你想徽章,声音和提醒您将包括此:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 

在:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

您可以添加这样的事情,以确保更新您的徽章:

NSString *badge = [apsInfo objectForKey:@"badge"]; 
application.applicationIconBadgeNumber = [badge intValue]; 

我个人也加入这样的代码,做我的处理在适当情况下:

[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedNotificationAlert" object:self]; 

上述工作适用于我所有的应用程序。你提到过,有些情况下你的应用未命中APN。你能分享到底什么样的情况?

相关问题