2013-03-19 60 views
0

我發送一個本地通知,一旦一個過程完成,它的行爲就好了。本地通知問題

這是我didReceiveLocalNotification代碼:

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

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

但是,當iPhone被鎖定的那些行不叫......我能做些什麼,使他們在後臺運行?

回答

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; 

}