didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我使用代码在 3 个地方检查 AppDelegate 类中的新消息:
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 可能不会一直通知应用程序有新通知。