Adding delay in sending SMS in iOS - iphone

I am developing an application that sends SMS to the selected contacts at regular intervals for a specified number of times. I have the SMS-sending functionality working, but I need to add a delay between sending SMS after each round.
For example, if I want a message M to be sent to S and D in my contacts, I need the app to wait for N seconds before sending the same message again to S and D.
How can I get this working? How do I add the delay function between sending the messages to the contacts?
Thanks in advance!

simply said, you can't.
It's not allowed to send messages yourself, you can only pop-up the sms-displayer and the user himself has to tap 'send'.
So if doing it programmatically in an app, this is not possible.
It might be possible if you're sending text messages using a server or something..

Would it be possible to set a NSTimer to go of for a certain number of times at certain intervals and have your app run in the background after it has been closed?
Make a timer:
int N = 3;
_myTimer = [NSTimer scheduledTimerWithTimeInterval:N target:self selector:#selector(myMethod) userInfo:myContact repeats:YES];
-(void)myMethod:(NSTimer*)timer {
// Now I can access all the properties and methods of myObject
[[timer userInfo] myObjectMethod];
}
Running in the background I am not as familiar with however if you start looking for beginBackgroundTaskWithExpirationHandler: Im sure you will find the answers that you need.
Hope this helps, Good Luck!

Well, if you have SMS sending functionality figured out then all you need is:
[self performSelector:#selector(sendSMS) withObject:nil afterDelay:5.0];
This is if your SMS data is somewhere in the model. If you need to send some data to your sendSMS method then use:
[self performSelector:#selector(sendSMS:) withObject:objectData afterDelay:5.0];

Related

Check a condition in the background every x minites, and if true, send notification

I've been looking for the solutions for several hours. I know how to use local notification. What I found is that local notification can be shown repeatedly, but the notification body and icon badge number should always be the same. What I want to do is: check a condition repeatedly even if the app is not running, if the condition is true, put a notification to the notification center, show a number to the app's icon badge. The number to show is got from database.
Does anybody know how to handle this? Any help will be appreciated.
Well you can do this, use nstimer and then run it every minutes after that inside timer selector write your condition to check after that on the basis of that post notification.
[NSTimer scheduledTimerWithTimeInterval:1
target:self select:#selector(sendnotification:) userInfo:nil repeats:YES];
-(void)sendnotification:(Nstimer*)timer
{
//post notification here
}

multitasking in ios 4 later for notifications

i want to run one of my services in the background even my app is in foreground or background states,if i get any data from that service i want to show that one as a notification to the user. how can i proceed .
as my reserach gives me an idea to follow multi taking in iphone .
or shall i use any timer so that the method calls for particular time interval for every time
NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:#selector(notification) userInfo:nil repeats:YES];
[timer fire];
-(void)notification
{
//shall i write all of my services here
}
or shall i create any new threads like
[self performSelectorInBackground:#selector(notification) withObject:Nil];
in AppDelegate file .
or shall i need to follow any other thing plz guide me thank you.
Generally, you should consider using push notifications sent by the server to show notifications to the user when something changes. This is preferable to running in the background since it is better for system performance & battery life.

How to disable UILocalNotification in iPhone for some time?

I have implemented one reminder iphone applicaion in which I have used local notification for reminder.
In this application their one functionality alert on/off.
So when user set on then user get notification and if its off then user can get notification.
I have done googling but not got sucess.
Can you give me idea for that is it possible or not.
Thanks in advance
Do you have other notifications in your appln.
If you don't have other notification in your app than,
Do one thing,
When you set OFF
- cancel all the notification
- calculate the time difference of current time & your notification firing time. set this in to some variable.
when you set it ON
- reschedule your Notification based on the time which you have saved earlier.
I am considering that you know how UISwitch works, according to switch position
UILocalNotification *localNotif;
//if switch is on
localNotif = [[UILocalNotification alloc] init];
//else if localNotif is not equal to null then
localNotif = nil;
You can start a timer which continuously check switch position and do the above stuff that depends on your coding.

Objective-c Don't pause while entering in background

is it possible not to pause the application while in background mode (when you press the home button and the app minimizes)? I have some timers and variables that i don't want to get paused.
EDIT:
I have followed this example http://evilrockhopper.com/2010/01/iphone-development-keeping-the-ui-responsive-and-a-background-thread-pattern/
I have called a timer inside however it's not getting called when i enter background mode:
- (void)applicationDidEnterBackground:(UIApplication *)application {
if(self.viewController.timerquest != NULL)
{
if(self.viewController.timerquest.timerRunning){
// Save varibales
[self performSelectorInBackground:#selector(performLongTaskInBackground) withObject:nil];
}
}
}
- (void) performLongTaskInBackground
{
// Set up a pool for the background task.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// perform some long task here, say fetching some data over the web.
//...
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(updateTimer) userInfo:nil repeats:YES];
// Always update the components back on the main UI thread.
[self performSelectorOnMainThread:#selector(completeLongRunningTask) withObject:nil waitUntilDone:YES];
[pool release];
}
-(void) updateTimer{
// Update my timer. This method is not being called in background mode
}
What should I do?
Thanks.
use Long Running Background tasks according to manual: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
Have a read here at the Apple non-technical documentation or at the technical reference.
Could you replace the timer with delayed background notifications?
Depending on what happens when your timers fire, you want to set up a local notification that fires at the same time the timer would have; this is useful when the timer would present something for the user to act on. As far as saving variables, you'll want to use -applicationDidEnterBackground: to save whatever state you need to, so that the correct variables can be loaded/generated when the app relaunches (which may not happen until the app has been exited and completely restarted again).
The types of tasks that are allowed to perform long running background tasks are pretty limited, specifically for things like GPS and playing audio. Everything else needs to decide on a task-by-task basis whether to simulate continued running (such as turning a timer to a local notification), pausing and saving necessary state to continue the next time the app is run, simply cancelling the task and gracefully restarting/notifying the user upon resuming the app, or asking for a finite length of time to finish a task (for things like finishing a download).

Doing some downloading without blocking you app

I'm working on my first app that's doing a few different web connections at once.
My first screen is my Menu.
And at the bottom of viewDidLoad of MenuViewController i call a method that gets and parses a .xml file that is located on my webserver.
Also at the bottom of viewDidLoad i do
FootballScores = [[FootBallScores alloc] init];
and FootballScores makes a connection to a html page which it loads into a string and then parses out data.
Now since both of these are getting called at the bottom of viewDidLoad of the class thats is responsible for the main menu(first screen in the app) it means the app is kinda slow to load.
What is the right way to do the above? Should i remove the 2 pieces of code from my viewDidLoad and replace with maybe
dataGetterOne = [NSTimer scheduledTimerWithTimeInterval:1.000 target:self
selector:#selector(xmlParser) userInfo:nil repeats:NO];
dataGetterTwo = [NSTimer scheduledTimerWithTimeInterval:2.000 target:self
selector:#selector(htmlParser) userInfo:nil repeats:NO];
This would mean that the methods get called later on and the viewDidLoad gets to finish before the i try get the data from the web servers.
Making 2 connections to we bservers a second apart to quick? Can the iphone handle having 2 connections open at once?
I'm really unsure of anything bad/dangerous I am doing in regards to connections.
Many Thanks
-Code
Try using ASIHTTPRequest. It's easy to use and lets you make asynchronous requests that don't block your app with few lines of code.
Hope this helps,
ender
Also, I wrote a brief tutorial on writing your own XML/JSON data-parsing app. I hope it may be helpful in thinking about how to structure such an app.