Objective c UILocalnotification未启动

Objective c UILocalnotification未启动,objective-c,Objective C,因为我不能得到一个很好的答案,而且花了很多时间在这个问题上,所以我会详细地问我的问题 我只想根据日期选择器创建一个警报。 从现在起将警报设置为10秒,效果非常好。 UIDatePicker,is works(打印日期,但不是我选择的日期,而是3小时后) 我知道《当地时报》有问题,但我就是找不到任何好的解释 我的建议是,我猜几乎每个人都不会参与当地时间,而是根据每个用户的时间来设置闹钟 我的代码不起作用,我不知道为什么。它没有开火(只有在我将其设置为10秒后) 拜托,我知道时区应该是不同的,但如果

因为我不能得到一个很好的答案,而且花了很多时间在这个问题上,所以我会详细地问我的问题

我只想根据日期选择器创建一个警报。 从现在起将警报设置为10秒,效果非常好。 UIDatePicker,is works(打印日期,但不是我选择的日期,而是3小时后) 我知道《当地时报》有问题,但我就是找不到任何好的解释

我的建议是,我猜几乎每个人都不会参与当地时间,而是根据每个用户的时间来设置闹钟

我的代码不起作用,我不知道为什么。它没有开火(只有在我将其设置为10秒后)

拜托,我知道时区应该是不同的,但如果你能解释清楚该怎么做,怎么做,那就太好了。谢谢

代码如下:

-(void)setDatePicker
{
    CGRect pickerFrame = CGRectMake(0,265,0,0);

    UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
    [myPicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];


   [[[CCDirector sharedDirector] view] addSubview:myPicker];
     [myPicker release];
}



-(void)pickerChanged:(UIDatePicker*) datePicker
{


     date=datePicker.date;

     NSLog(@"value: %@",date);
}
以及本地通知:

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



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

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


//NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
//[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
//NSDate *notificationDate = [dateFormat stringFromDate:theDate];


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

localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = [NSString stringWithFormat:
                               @"Your notification message"];
localNotification.alertAction = NSLocalizedString(@"View details", nil);



localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = -1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
我明白了

我不得不改变格式,结果成功了。 与区域无关

NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
     [dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *dateString = [dateFormat stringFromDate:date];
    NSDate *notificationDate = [dateFormat dateFromString:dateString];


    localNotification.fireDate = notificationDate;