0

流程完成后,我将发送本地通知,并且效果很好。

这是我的 didReceiveLocalNotification 代码:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

    CounterViewController *counterVC = [CounterViewController sharedInstance];
    [counterVC notificationArrived];
}

但是当 iPhone 被锁定时,这些行不会被调用……我该怎么做才能让它们在后台运行?

4

1 回答 1

1

有两种接收本地通知的方法,一种是您已经实现,它在应用程序运行时调用,第二种是在应用程序运行时调用的 didFinishLaunchingWithOptions 中,您添加了一些代码来接收本地通知.....

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

// Add the view controller's view to the window and display.


application.applicationIconBadgeNumber = 0;

// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
    NSLog(@"Recieved Notification %@",localNotif);
}

return YES;

}

于 2013-03-19T10:55:37.640 回答