2012-04-24 15 views
0

私はiOSのチャットアプリケーションを開発しています。私は地元の通知に問題がありました。アプリケーションがバックグラウンド状態に行ってきました 、私はこのコードを使用しています:アクティブなアプリケーションをiphoneローカル通知

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.alertAction = @"Ok"; 
    localNotification.alertBody = [NSString stringWithFormat:@"From: %@\n%@",message.sender,message.message]; 

    [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    [localNotification release]; 

が、アプリケーションがアクティブな状態であり、そしてそれは私が地元の通知を必要とするも、その後のチャットページではありませんが、私はそこに同じコードを使用する場合また 通知は、トレイに来ているが、バナーは以下の方法

答えて

0

次のコードの通知は、アラートとして来ている

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    [self showNotificationAlert:notification.alertBody]; 
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    NSString *alertMsg = nil; 
    id alert = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]; 

    if ([alert isKindOfClass:NSString.class]) 
     alertMsg = alert; 
    else if ([alert isKindOfClass:NSDictionary.class]) 
     alertMsg = [alert objectForKey:@"body"]; 

    [self showNotificationAlert:alertMsg]; 
} 

- (void)showNotificationAlert:(NSString *)alertMsg 
{ 
    if (!alertMsg) 
     return; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Message", nil) 
                message:alertMsg 
                delegate:self cancelButtonTitle:NSLocalizedString(@"OK", nil) 
              otherButtonTitles:nil]; 
    [alert show]; 

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0; 
} 
1

は、アプリケーションの委任

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    UILocalNotification *localNotif =notification; 
    NSString *strBody=[localNotif.userInfo valueForKey:@"Body"]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your Application name" 
                message:strBody 
                delegate:self cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil]; 
    [alert show]; 

    //NSLog(@"Incoming notification in running app"); 

    // Access the payload content 
    //NSLog(@"Notification payload: %@", [notification.userInfo objectForKey:@"body"]); 

    application.applicationIconBadgeNumber = 0; 
} 
に入れ...

私を助けてください....来ていません

+0

リモートとローカルの両方の通知を処理する通知が牡羊座いるとき、何が必要であることは、この方法ではバナー –

+0

べきであるとアラートを示していた時間。 この情報が役に立ちます。 –

関連する問題