2017-06-11 3 views
0

を働いていません作成します - 私はfiredateをプリントアウトしており、その私がしたい正確に何以下はUILocalNotificationを作成するための私の方法ですUILocalNotificationは

-(void)addNewNotification{ 
    //snooze for 1 minute 
    NSMutableDictionary *myUserInfo = [[NSMutableDictionary alloc]init]; 
    [myUserInfo setObject:@"Snooze reminder" forKey:@"infoID"]; 
    //1 for Meds 
    //2 for Cream 
    [myUserInfo setObject:[NSNumber numberWithInt:2] forKey:@"MedType"]; 
    [myUserInfo setObject:self.reminderTimeString forKey:@"ReminderTime"]; 

    NSString *alertText = [NSString stringWithFormat:@"Cream time at %@",self.reminderTimeString]; 
    UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    localNotification.alertBody = alertText; 
    localNotification.userInfo = myUserInfo; 
    localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:2*60]; 
    localNotification.timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 
    localNotification.applicationIconBadgeNumber = 1; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    NSLog(@"%@",[[UIApplication sharedApplication] scheduledLocalNotifications]); 
} 

。しかし、問題は、通知が時間が過ぎても起動しないということです。 ローカル通知を正しく追加していますか?

+0

この行は、 'localNotification.timeZone = [NSTimeZone timeZoneWithName:@" GMT "];'として試してみてください。 –

答えて

0

ローカル通知を登録していない可能性がありますか?あなたのアプリは通知を使用する許可を要求していますか?

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
+0

私はそれをしました、それはタイムゾーンの問題のためでした。私がしなければならなかったのは、単にタイムゾーンを削除することでした – SPUDERMAN

関連する問題