2013-03-20 3 views
0

로컬 알림을 설정했습니다. 해고 당하면 내 앱이 집 버튼을 눌렀을 때 "잠자기"모드에 있다고 말하거나 종료합니다. 이제 알림이 수신됩니다. 내 앱에 빨간색 태그가 표시되고 앱을 클릭하면 didReceiveLocalNotification을 실행해야하지만 그렇지 않습니다. 앱을 열 때 어떻게 할 수 있습니까?로컬 알림 앱이 열릴 때 표시되지 않음

답변

1

didReceiveLocalNotification 메서드는 응용 프로그램이 포 그라운드에서 실행될 때만 호출됩니다. 배지를보고 앱을 클릭하여 시작하면 application:willFinishLaunchingWithOptions: (또는 application:didFinishLaunchingWithOptions:)을 사용하여 로컬 알림을 처리해야합니다. 두 가지 방법 중 하나에서 로컬 알림을 받으려면 UIApplicationLaunchOptionsLocalNotificationKey을 옵션 사전의 키로 사용하십시오 .

UILocalNotification 문서에서 [편집] :

로컬 알림은 응용 프로그램 아이콘 배지 및 응답의 사용자가 응용 프로그램의 응용 프로그램을 실행하는 경우 : didFinishLaunchingWithOptions를 : 메소드가 호출,하지만 UILocalNotification 개체가 옵션 사전에 포함되어 있습니다.

+0

시작 옵션이 nil을 반환합니다 ..... 알림 표시 줄에 알림을 볼 수 있지만 실행 옵션이 응용 프로그램을 열 때 nil을 반환합니다 –

+0

launchOptions 사전이 nil입니까? 그렇지 않다면 그 내용은 무엇입니까? – GoZoner

+0

틀렸어. 그것은 없습니다. 그것은 뭔가를 반환해야합니다. didEnterBackground에 간단한 알림을 넣으려고했습니다. 열린 된 응용 프로그램, 홈 버튼을 눌렀습니다. Xcode를 사용하여 응용 프로그램을 종료 한 다음 알림을받은 후 Xcode를 사용하여 다시 테스트하십시오. 아직도 없다. –

0
-(void)alarmNotification 
    { 
     NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 

     NSDate *newdate = timePicker.date; 

     NSLog(@"pickerdate:%@",newdate); 

     NSDate *pickerDate =[newdate dateByAddingTimeInterval:-60*1]; 

     NSLog(@"pickerdate:%@",timePicker.date); 

     // Break the date up into components 
     NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit |  NSMonthCalendarUnit | NSDayCalendarUnit) 
                fromDate:pickerDate]; 
     NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
               fromDate:pickerDate]; 
    // Set up the fire time 
     NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
    [dateComps setDay:[dateComponents day]]; 
    [dateComps setMonth:[dateComponents month]]; 
    [dateComps setYear:[dateComponents year]]; 
    [dateComps setHour:[timeComponents hour]]; 
    // Notification will fire in one minute 
    [dateComps setMinute:[timeComponents minute]]; 
    [dateComps setSecond:[timeComponents second]]; 
     NSDate *itemDate = [calendar dateFromComponents:dateComps]; 
     [dateComps release]; 

     localNotif = [[UILocalNotification alloc] init]; 
     if (localNotif == nil) 
     return; 
     localNotif.fireDate = itemDate; 
     localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

    // Notification details 
     localNotif.alertBody = txtMeetingName.text; 

    // Set the action button 
     localNotif.alertAction = NSLocalizedString(@"View!", nil); 

     localNotif.soundName = UILocalNotificationDefaultSoundName; 

     // Specify custom data for the notification 
     NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; 
     localNotif.userInfo = infoDict; 

     localNotif.applicationIconBadgeNumber =1; 

     [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 


     } 

그런

+1

didLinunchOptions에서 가져오고 싶습니다. didReceive와 잘 작동합니다. 사실 앱이 닫히고 정상적으로 열리면 푸시 알림과 달리 launchOptons에 나타나지 않습니다 –

0

당신이 화재 날짜를 설정하는 경우 다음이 가지고 ......이 당신을 도울 것입니다

 - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { 
    // Handle the notificaton when the app is running 
     NSDateComponents *comps = [[NSCalendar currentCalendar] components:notif.repeatInterval fromDate:notif.fireDate toDate:[NSDate date] options:0]; 
    // you can set your own sound 
     NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/win.wav", [[NSBundle mainBundle] resourcePath]]]; 

    NSError *error; 

     UIAlertView *alertView = 
    [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"move on", nil) 
          message:[NSString stringWithFormat:@"You have to start %@ meeting within 5 minute",notif.alertBody] 
          delegate:self 
       cancelButtonTitle:nil 
       otherButtonTitles:NSLocalizedString(@"OK", nil), nil]; 

     notif.soundName = UILocalNotificationDefaultSoundName; 


     audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
     audioPlayer.numberOfLoops = -1; 
     if (audioPlayer == nil) 
     NSLog(@"error%@",[error description]); 
     else 
     [audioPlayer play]; 
     [alertView show]; 
     [alertView release]; 

    } 


    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:  (NSInteger)buttonIndex{ 
    if (buttonIndex==0) { 
    [audioPlayer stop];  

    } 
    NSLog(@"U HAVE CLICKED BUTTON"); 
} 

희망을 .....이 코드를 구현 알림 개체의 userInfo 속성을 설정 하시겠습니까 ??? & 기기 또는 시뮬레이터에서 확인 하시겠습니까 ??

+0

알림이 시작됩니다. 알림을 클릭하면 didReceiveNotification이 호출됩니다. 그러나 응용 프로그램이 닫힐 때 밀어 넣기 알림과 달리 didFinishWithLaunchOptions의 실행 프로그램 옵션에 표시되지 않습니다. –

+0

그래도 .. 알림 개체의 userinfo 속성을 설정 했습니까 ?? – Kalyani

+0

@MuhammadUmar & 시뮬레이터 또는 실제 장치에서 테스트하기 – Kalyani

관련 문제