2012-04-29 20 views
2

アプリがバックグラウンドにある間に地域を入力すると、場所のアップデート、テストの実行のためにアプリが登録されています。いつか私は通知センターで通知を見るだけで、私はどんな音や警告も受けていませんでした。 いつも音と警告の通知を受けるために何ができますか?Iphone presentLocalNotification Nowはアプリをバックグラウンドで起動している間、アラートやサウンドを起動しません。

これは私が私の見解で持っているもの

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
localNotif.fireDate    = nil; 
localNotif.hasAction   = YES; 
localNotif.alertBody   = fbName; 
localNotif.alertAction   = @"View"; 
localNotif.soundName   = UILocalNotificationDefaultSoundName; 

[[UIApplication sharedApplication]presentLocalNotificationNow:localNotif]; 

であり、アプリケーションがバックグラウンドで実行されている場合、このアプリのデリゲート

- (void)application:(UIApplication *)application didReceiveLocalNotification (UILocalNotification *)notification 
{ 
if (notification) 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" 
                message:notification.alertBody 
                delegate:self cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 


    [alertView show]; 

} 

} 

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

{

facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self]; 

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 

if (notification) 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" 
                 message:notification.alertBody 
                 delegate:self cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 


    [alertView show]; 

} 



return YES; 
} 
+0

[UILocalnotificationアプリケーションがバックグラウンドにあるときに表示されない]の可能な重複(http://stackoverflow.com/questions/10367400/uilocalnotification-is-not-appearing-when-the-application-is -in-the-background) –

+0

私はこれが全く同じだとは思わない、それはいくつかのケースで動作するように、それは私のために背景にあった時間とは関係があるようだ、それは状態の周りを回るそのアプリケーションがバックグラウンドでUILocalNotificationの動作が矛盾しているように見える場合は誰でもこれを体験できますか? – Brett

答えて

3

あり、ローカル通知は、アプリケーションから直接受信されるため、アラートやサウンドを取得しません。その場合は、presentLocalNotificationNowを使用して通知を提示する必要があります。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    UIApplicationState applicationState = application.applicationState; 
    if (applicationState == UIApplicationStateBackground) { 
     [application presentLocalNotificationNow:notification]; 
    } 
} 
+2

presentLocalNotificationNowを呼びたいとは思わない。これは即時にローカル通知を送信するためのものです。あなたはおそらくここで私は信じて無限ループを得るだろう。 –

+1

'presentLocalNotificationNow:'はローカル通知のみを表示し、再通知しません。 –

関連する問題