mitul marsonia mitul marsonia - 3 months ago 23
iOS Question

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.

Answer

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];
Comments