【发布时间】:2014-06-21 15:13:06
【问题描述】:
(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo ;
和
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult
result))completionHandler{};
从来没有被调用,虽然我在 iphone 上收到通知,是否需要添加任何其他功能才能使其正常工作?谢谢。
更新 当应用程序不在后台也不处于活动状态但我没有收到消息时,我尝试了这个。 - (BOOL)应用程序:(UIApplication *)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 为 |GPPSignIn| 设置应用程序的客户端 ID和 |GPPShare|。
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// Clear application badge when app launches
application.applicationIconBadgeNumber = 0;
if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {
id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"MESSAGE" message:userInfo delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
}
【问题讨论】:
-
此方法在应用程序处于活动状态或背景时调用,如果您的应用程序关闭则此方法永远不会调用。
-
那么,如果应用程序不在后台或处于活动状态,我可以实现任何功能来接收推送通知吗?
-
是的,在 didFinishLaunchingWithOptions..
-
请确定,您的应用程序是在后台还是前台?如果它在前台,我确定调用了该方法。如果不是,则可能您没有将该方法放入您的应用程序委托中。
标签: ios push-notification