2012-01-22 2 views
2

문제는 내 알림이 설정 될 때까지 진행되지 않는다는 것입니다. 펜촉에 날짜 선택기를 놓고 그 아래에 단추를 놓습니다. 사용자는 피커에서 날짜를 설정하고 버튼을 클릭하여 날짜보다 60 시간 전에 알림을 설정합니다. 그래서, 나는 데이트 피커에서 날짜를 인식하도록 해고를하는 데 문제가있는 것처럼 보입니다. 이것은 사용자가 입력 선택기에서 날짜를 저장 다루는 내보기 컨트롤러에서 더 많은 코드,iOS : 지역 알림이 발효하지 않습니다.

- (IBAction)scheduleNotifButton:(id)sender { 
UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 

NSDate *selectedDate = [self.datePicker date]; 


localNotif.fireDate = [selectedDate dateByAddingTimeInterval:-60*60*60]; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 


localNotif.alertBody = @"Event is in three days!"; 

localNotif.alertAction = nil; 

localNotif.soundName = UILocalNotificationDefaultSoundName; 
localNotif.applicationIconBadgeNumber = 0; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];  

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Event scheduled." 
               message:@"You will be notified three days before the event." 
               delegate:nil 
             cancelButtonTitle:@"Okay." 
             otherButtonTitles:nil]; 
[alert show]; 

} 

을 그리고 여기에 도움이된다면 몇 가지 추가 코드 : 여기, 내보기 컨트롤러에 코드입니다 : 지금 3 일이 코드를 통해 파고 봤는데 그들이에 가정 할 때 내 알림을 통해하지 않을 이유를 알아낼 수 없습니다

- (IBAction)dateChanged:(id)sender 
{ 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    NSDate *selectedDate = [self.datePicker date]; 

    [defaults setObject:selectedDate forKey:@"ImportantDatesViewController.selectedDate"]; 
    [defaults synchronize]; 

} 
- (void)viewDidLoad { 
    NSDate *storedDate = [[NSUserDefaults standardUserDefaults] 
          objectForKey:@"ImportantDatesViewController.selectedDate"]; 
    if (storedDate == nil) { 
     storedDate = [NSDate date]; 
    } 

    [self.datePicker setDate:storedDate animated:NO]; 

} 

. 어떤 도움이라도 대단히 감사합니다. 감사합니다!

답변

3

UILocalNotifications와 원격 알림이 다른 점을 알고 있습니까?

didRegisterForRemoteNotificationsWithDeviceToken에서 원격 알림에 사용할 장치 토큰을 가져옵니다. 원격 알림은 서버에서 전송되므로 토큰을 서버에 저장 한 다음 서버를 사용하여 원격 알림을 보내야합니다.

왜이 변경되지 않습니다

localNotif.fireDate = [eventDate dateByAddingTimeInterval:-630*60]; 

이에 :

localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:60]; 

그런 다음 로컬 알림 분에 꺼한다. 어쩌면 문제는 당신이 설정하고있는 날짜입니다.

+0

감사합니다. 경고를 보내지 만, 사용자가 피커에 입력 한 날짜에 전혀 의존하지 않는 것 같습니다. – John

1

알림이 작동하지 않는다는 것을 어떻게 알 수 있습니까?

로컬 및 푸시 알림이 다릅니다. 앱이 현재 활성화되어 있다면 로컬 알림에 경고 메시지가 실제로 표시되지 않습니다. 그냥 UIApplicationDelegateMethod를 호출합니다.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
+0

그래, 그게 원인이되어야 해. 어쨌든이 경우 경고를 표시하려면 수동으로 UIAlert를 만들고 해당 (-) void 응용 프로그램 : (UIApplication *) application didReceiveLocalNotification : (UILocalNotification *) notification' 메서드 내에 수동으로 표시 할 수 있습니다. – Hlung

관련 문제