我在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有新的通知。