2014-12-10 3 views
0

다음 코드를 사용하여 특정 시간에 로컬 알림을 보냈습니다. 메서드에서 호출 할 때 잘 작동하지만 다른 메서드에서 호출 할 때 작동하지 않습니다.알림 fireTime이 작동하지 않습니다.

코드를 다음과 같이 사전에

-(void)notificationUserInfo:(NSDictionary *)notificationData 
{ 
UILocalNotification *notification = [[UILocalNotification alloc] init]; 
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm"]; 

NSString *tipid = [notificationData objectForKey:@"receivedTipsId"]; 
NSString *currentDate = [notificationData objectForKey:@"receivedDate"]; 
NSString *tipsCategoryid = [notificationData objectForKey:@"categoryId"]; 
NSString *todayDateTime = [notificationData objectForKey:@"todayDate"]; 
NSString *categoryName = [notificationData objectForKey:@"categoryName"]; 
NSString *tipsForNotification = [notificationData objectForKey:@"tipsForNotification"]; 
NSString *cardType = [notificationData objectForKey:@"cardType"]; 

//Assigning the notification contents 
NSDate *updatedDateFormat = [dateFormat dateFromString:todayDateTime]; 
notification.fireDate = updatedDateFormat; 
notification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:tipid, @"receivedTipsId", currentDate, @"receivedDate", tipsCategoryid, @"categoryId", cardType, @"cardType", nil]; 
notification.alertBody = [NSString stringWithFormat:@"%@: %@",categoryName, tipsForNotification]; 
notification.soundName = UILocalNotificationDefaultSoundName; 
notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; 
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
} 

감사합니다.

답변

0

시간 및 날짜 형식 문제 때문입니다. 내가이 방법을 사용했을 때, 나는 해고 된 날짜를 과거 날짜로 지정했습니다. 예 : dd/MM/yyyy 대신 MM/dd/yyyy을 사용했습니다.

따라서 11/12/201412/11/2014으로 반환됩니다. 따라서 통지는 예정된 통지 직후에 수신됩니다.

0

iOS 8에서 사용하는 경우 로컬 알림을 위해 앱을 등록해야합니다.

애플 대리자

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /*...*/ } 

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) 
{ 
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]]; 
} 

IN

그리고

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler 
+0

나는 이미 그랬다. –

0
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    if (!localNotification) { 
     break; 
    } 
    **localNotification.timeZone = [NSTimeZone defaultTimeZone];** 

    [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:20]]; 
    localNotification.alertBody = @"message"; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

위의 코드를 사용.

관련 문제