我已经实现application:didReceiveRemoteNotification:了在收到推送通知时在我的应用中存储数据.
但是,当我的应用程序处于后台并且收到通知时,仅当我触摸顶部显示的通知横幅时才会存储数据:
相反,如果我触摸应用程序图标以重新打开它,则不会存储通知的内容:
application:didReceiveRemoteNotification: 仅当我将通知横幅推到顶部时才会调用.
我已经使用applicationWillEnterForeground和didFinishLaunchingWithOptions方法,同时单击应用程序图标并调试其输入applicationWillEnterForeground和控制无处可去.这是didFinishLaunchingWithOptions和applicationWillEnterForeground和的代码didReceiveRemoteNotification.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
self.isForeground = YES;
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
storage= [[NSMutableArray alloc]init];
if (launchOptions …Run Code Online (Sandbox Code Playgroud)