本地通知不与NSDate字符串链接

时间:2014-07-18 16:18:48

标签: ios objective-c nsdate uialertview uialertviewdelegate

我的问题是我的申请通知。

我正在为我的音乐应用使用提醒通知,因此人们可以在播放节目前两小时收到通知。我之前测试过类似的代码,但是使用整数组件而不是NSString日期,并且它有效。但是,我需要在此特定实例中使用字符串。

对我来说,一切看起来都应该有效。位于单例内的NSLog输出正确的信息。例如。 =

NSLog(@"Notification will be shown on: 2014-07-18 11:03:00 +0000)

那为什么我没有收到通知?我已经尝试了一段时间,整天都遇到了障碍。希望得到一些帮助。

谢谢!

- (void)scheduleNotificationForDate:(NSDate *)date {

    // Here we cancel all previously scheduled notifications
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = date;
    NSLog(@"Notification will be shown on: %@",localNotification.fireDate);

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = [NSString stringWithFormat:@"Aurora Radio plays in 2 hours!"];
    localNotification.alertAction = NSLocalizedString(@"View details", nil);

    /* Here we set notification sound and badge on the app's icon "-1"
       means that number indicator on the badge will be decreased by one
       - so there will be no badge on the icon 
    */
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

IBAction为=

-(IBAction)setReminder {

    // Setting all the information about our date
    NSString * dateString = @"2014-07-18 11:03:00";

    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    NSDate *myNewDate = [dateFormatter dateFromString:dateString];

    [self scheduleNotificationForDate:myNewDate];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Aurora Radio"
                                                message:@"Alarm has been set two hours prior to performance!"
                                               delegate:self
                                      cancelButtonTitle:@"Sounds good bros, see you later."
                                      otherButtonTitles:nil];
    [alert show];
}

0 个答案:

没有答案