Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

Local notification set default time 9:00 am for user timezone in iOS

I want set notification default 9:00 am for every user timezone time.

How to create fire date for default time 9:00 am.

Upvotes: 2

Views: 1347

Answers (3)

Renish Dadhaniya
Renish Dadhaniya

Reputation: 10752

  1. This is a full tutorial regarding Local Notification

  2. Below is Solve issue of timezone which mention above. Please review these timezone function in details and set appropriate timezone in your function.


[NSTimeZone defaultTimeZone]

[NSTimeZone systemTimeZone]

[NSTimeZone localTimeZone]

NSTimeZone: what is the difference between localTimeZone and systemTimeZone?

Upvotes: 0

Om Prakash
Om Prakash

Reputation: 9461

Try this code.

 NSDate *pickerDate = [date_picker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = @"Alert Body Message";
localNotification.alertAction = @"Alert Action Message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Upvotes: 0

Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

Hello I got it this Ans:-

NSDate *pickerDate = [NSDate date]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:DT_FORMATE_BIRTHDATE];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:DT_TIME_ZONE_GMT];
    [dateFormatter setTimeZone:gmt];

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *timeComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
                                                   fromDate:pickerDate];
    [timeComponents setHour:9];
    [timeComponents setMinute:00];
    [timeComponents setSecond:0];

    NSDate *dtFinal = [calendar dateFromComponents:timeComponents];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];

    NSString *fierDate = [formatter stringFromDate:dtFinal];

Upvotes: 1

Related Questions