Guest User

Untitled

a guest
Jul 12th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     NSDate *currentDate=[NSDate date];
  2.     NSString *dateStr=@"6:32 PM";
  3.    
  4.     NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  5.     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  6.     [dateFormatter setDateFormat:@"hh:mm a"];
  7.     [dateFormatter setTimeZone:gmt];
  8.    
  9.     [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  10.     NSString *preFix=[dateFormatter stringFromDate:currentDate];
  11.     NSString *datetoFire=[NSString stringWithFormat:@"%@ %@",preFix,dateStr];
  12.    
  13.     [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
  14.    
  15.     NSLog(@"date is %@",[dateFormatter dateFromString:datetoFire]);
  16.      
  17.  
  18.     [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  19.     [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  20.     NSDate *fireDate = [dateFormatter dateFromString:datetoFire];
  21.    
  22.    
  23.     // Cancel the previously scheduled notification, if any.
  24.     if (localNotification != nil) {
  25.         [[UIApplication sharedApplication] cancelLocalNotification:localNotification];
  26.         localNotification.applicationIconBadgeNumber--;
  27.     }
  28.    
  29.    
  30.     NSLog(@"Fire date is %@",fireDate);
  31.    
  32.     // Schedule new local notification.
  33.     localNotification = [[UILocalNotification alloc] init];
  34.     localNotification.alertBody = @"This is notification demo";
  35.     localNotification.alertAction = @"See Me";
  36.     localNotification.fireDate = fireDate;
  37.     localNotification.soundName = UILocalNotificationDefaultSoundName;
  38.     localNotification.applicationIconBadgeNumber++;
  39.     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
  40.    
  41.     [scheduleTextField resignFirstResponder];
Advertisement
Add Comment
Please, Sign In to add comment