1

I am creating an application where user can send an SMS to the Recipient, and it is working fine. But I want to send Message at a scheduled time. For this I have two picker views, from one picker sender we can set date and from other sender can set time as I have shown in the attached screenshot.

How to trigger send button or send the sms at a scheduled time? Can I use an NSTimer?

enter image description here

Any help would be greatly appreciated. Thank you. If someone have any doubt related to question then let me know.

Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76
Anand Gautam
  • 2,541
  • 3
  • 34
  • 70

2 Answers2

1

You can use NSTimer to schedule message.

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

here you can pass target as Your view controller that has sms sending functionality and selector will be your action method that gets called on sms button click.

But problem with NSTimer is that it stops when App is in background.If you have such requirement then NSTimer will not be useful.

JiteshW
  • 2,195
  • 4
  • 32
  • 61
Ganesh Amrule
  • 407
  • 2
  • 12
  • What about using local notification instead of NSTimer? I haven't used, but just for curiosity...it will work, rt? – HRM Aug 27 '13 at 05:50
  • Local notification are delivered only when app is in background.App will not receive local notification in foreground mode. – Ganesh Amrule Aug 27 '13 at 06:00
  • No,i think only notification wont be displayed when app in foreground, but didReceiveRemoteNotification will be invoked in both cases from which he can send sms. – HRM Aug 27 '13 at 06:05
  • Thanks to all for giving me time.Finally i am using NSTimer but the problem is how to calculate NSTimeInterval in seconds? According to my requirement i can't use Local notification. – Anand Gautam Aug 27 '13 at 06:09
  • NSTimeInterval is itself in seconds. – Ganesh Amrule Aug 27 '13 at 06:43
1

You can use NSTimer in background also... You need to make some changes in appDelegate... Follow the below link to make your app wait for background task to complete beginBackgroundTaskWithExpirationHandler for long time in background try (more than 10 min) How do I make my App run an NSTimer in the background?

Community
  • 1
  • 1
Mayur Kothawade
  • 544
  • 4
  • 14
  • But in this case timer will not work for too long. It will work for max 10 mins. – JiteshW Aug 27 '13 at 06:20
  • @Jitesh Your point is right, Application can stay in background for 10 min max, .....http://stackoverflow.com/questions/9220494/how-do-i-make-my-app-run-an-nstimer-in-the-background – Mayur Kothawade Aug 27 '13 at 07:03
  • @Anand are you using iphone SDK to send SMS?, Apple doesn't allow automatic sending of SMS... in that case You can see similar failed app on appstore https://itunes.apple.com/in/app/smartsender-schedule-your/id490395840?mt=8 – Mayur Kothawade Aug 27 '13 at 07:07