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