Hi, Every one.,, i'm new to iPhone application Development.
In my SMS sending application.
sent time and current time is equal then i can send message. if not that sent time is current time.
I need to send SMS on that specific time. For that how i need to store that SMS locally (Recipient No, Message, And Time (When to send) ).
Also when the specified time becomes equal to current time i need to activate my application. By Notification or alert.
my code is below
-(void)sendInAppSMS
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *pickerDate = [self->datePicker date];
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatInterval=1;
localNotif.alertBody = [textFieldRounded1 text];
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
NSLog(@"SendMessage");
if([textFieldRounded.text isEqualToString:@""] || [textFieldRounded1.text isEqualToString:@""] || [textFieldRounded2.text isEqualToString:@""] || [textFieldRounded.text isEqualToString:@"(null)"] || [textFieldRounded1.text isEqualToString:@"(null)"] || [textFieldRounded1.text isEqualToString:@"(null)"] || [textFieldRounded.text isEqualToString:nil] || [textFieldRounded1.text isEqualToString:nil]|| [textFieldRounded2.text isEqualToString:nil])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"SMS" message:@"Please Enter All Fields!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else
{
NSLog(@"Done");
NSDateFormatter *SentTime = [[NSDateFormatter alloc] init];
[SentTime setDateFormat:@"dd/MM/YYYY hh:mm aa"];
NSDate *now1 = [NSDate date];
NSString *Time1 = [SentTime stringFromDate:now1];
NSLog(@"Time is :%@",Time1);
NSString *Sentime=[NSString stringWithFormat:@"%@",textFieldRounded2.text];
if([Sentime isEqualToString:Time1])
{
NSLog(@"Time Matching... can send msg now");
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
NSString *Message = [NSString stringWithFormat:@"%@, %@",textFieldRounded1.text,textFieldRounded2.text];
NSLog(@"Message is %@", Message);
controller.body = Message;
controller.recipients = [NSArray arrayWithObjects:@"+919994442409" , nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
else
{
NSLog(@"Send Message when time reach at %@",textFieldRounded2.text);
NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
[textFieldRounded resignFirstResponder];
[textFieldRounded1 resignFirstResponder];
[textFieldRounded2 resignFirstResponder];
NSString *To = [textFieldRounded text];
NSString *Msg = [textFieldRounded1 text];
NSString *Timee = [textFieldRounded2 text];
[userDefault setValue:To forKey:@"receiptent"];
[userDefault setValue:Msg forKey:@"contentt"];
[userDefault setValue:Timee forKey:@"Tim"];
[userDefault synchronize];
NSLog(@"Data saved");
NSString *To1 = [userDefault valueForKey:@"receiptent"];
NSString *Msg1 = [userDefault valueForKey:@"contentt"];
NSString *Timee1 = [userDefault valueForKey:@"Tim"];
NSLog(@"Receiptent No: %@",To1);
NSLog(@"Message Content is : %@",Msg1);
NSLog(@"Sent Time Is : %@",Timee1);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"SMS" message:@"Message Will Send At Time" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}
Is it possible? please help me...