iPhone background app showing Call alert - iphone

I am new to iPhone programming and I have a question. If I have an application that needs to initiate a phone call at 11:00 AM, is it possible for the app to show a call alert to the user? so the user at 11 would see the number pop up with a call or cancel option. Thoughts? Also is this also possible if my app is not running in the background and If I have to initiate using push notification.

You can do this by using a local notification that will bring your application to foreground (well, sort of, an alert will be displayed that will allow the user to take the appropriate action).
In order to launch a phone call you are going to use the openURL method on the application object like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:12345689"]];

Related

iOS UILocalNotification not updating app icon

first of all, I'm really thankful for all your help.
I need just one more little help.
I finished my app, and I used UILocalNotifications to fire some reminders. The app icon is always with a "1" saying there is 1 new notification on the app but it is like that for ever, even if there is no notification. How can I fix this?
Other detail, when the user slides the app icon when iPhone fires the notification (outside the app when the iPhone is locked or when the app is in the background), I would like the app to load in the main view. Is it possible?
You can reset the badge number inside you application delegate code, in didFinishLaunchingWithOptions and didReceiveLocalNotification: as appropriate. i.e.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
I don't understand your second question.
If you want to change the view it displays depending upon how its launched then you can do so, once again this would be in didFinishLaunchingWithOptions or didReceiveLocalNotification.

Home button press , Which AppDelegate method should i use for scheduling a local notification

I would like to schedule a local notification as soon as the user hits the home button.
Which App delegate method should I use in this case :
applicationWillResignActive
applicationDidEnterBackground
applicationWillTerminate
Well I guess I shouldn't use the third one, but what is the difference between the first two ?
Is there any way to distinguish getting interrupted by a phone call/other notification and actually pressing the home button ?
Thanks in advance.
To schedule local notification you shold use applicationDidEnterBackground instead of using applicationWillResignActive because applicationWillResignActive call every time when app get some specific interruption line phone call, sms. You want to schedule notification when user press home button and in this case applicationDidEnterBackground is the appropriate place to do this.
One thing that should be remember before using applicationDidEnterBackground is that this delegate has approximately five seconds to perform any task, if any task in this delegate will take more time then os will terminate your app. You can also request for additional time for execution by using beginBackgroundTaskWithExpirationHandler and then use a secondary thread to perform a task. For more detail about application delegates follow the links -
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/
You should use applicationDidEnterBackground.
applicationWillResignActive gets called anytime your app is interrupted such as a phone call or SMS message. In this case if the user ignores these then your app will keep running in the foreground.
applicationDidEnterBackground only gets called when your app actually goes to the background.
You should do this in applicationDidEnterBackground:
applicationWillTerminate will not be
called when the user hits the home
button. With app switching this is
only sent when the user explicitly
quits the app or possibly in low
memory situations.
applicationWillResignActive is
additionally called when the app is
briefly interrupted, say by an SMS or
phone call alert. (Though if the user
then switches to Messages or Phone
app your app will eventually get a
applicationDidEnterBackground
message).
So it sounds like you're specifically interested in the point when the user taps the home button and the app goes to the background. applicationDidEnterBackground is the place.
You could also always schedule the local notification and only respond to it if the app isn't running when it occurs. Not better necessarily, just an option to consider.

I want eject any user action until a function is done, iphone app!

i'm writing an iphone app integrate with webservice.When user wait to login on web,I want eject any user action until login is done. Please help me! thanks!
One way would be to pop up a modal view controller using presentModalViewController. Another way would be to use [[UIApplication sharedApplication] beginIgnoringInteractionEvents]
If you don't multithread your code the user shouldn't be able to interact with your UI while you're getting and sending data.
Alternatively you could present a semitransparent loading screen over the whole UI -while loading- that intercepts every touch event.

Is there a way to make my background iPhone app to go foreground?

Is there a way to make my background iPhone app to go foreground?
Tnx.
A UILocalNotification will bring the app to the foreground if the device is locked, a notification appears, and the user unlocks the device.
A UILocalNotification with an alertAction will display the alert while the device is unlocked, and if the user taps the View button (or whatever you set it to), your app will be brought to the front.
Not for your app, but the user could do it.
You could schedule a UILocalNotification to inform the user that you are done with your task or whatever.
Nope. But you can do something when you feel must do. For example, use remote Apple Push Notification Service (APNS) to notify your user that you want her to bring your app back to the foreground.
Or, as JustSid put it, use local notification to notify your user that you want her attention.

How to close an application programmatically when the user taps on a button

I need to close the application whenever user taps on the button(i need to keep IBAction for closing the app).Like in games menu we have exit button when we tap on it we come out from the game.Same thing i need.How can i do this .Thanks in advance
Please see:
How do I programmatically quit my iPhone application?
WARNING: It is possible to quit the
application by calling exit.
Applications calling exit will appear
to the user to have crashed, rather
than performing a graceful termination
and animating back to the Home screen.
Such usage provides a negative
experience and is strongly
discouraged.
Instead of it, If you want your app to terminate when the user presses the home button, set the value of UIApplicationExitsOnSuspend to YES in your app's Info.plist file. If you do this, when the user taps the home button the applicationWillTerminate: method of your app delegate will be called and then your application will terminate.
exit(0); will terminate your application, but as i know we can not call exit(0); or terminate in an iPhone application. Instead we can put an alerview without button, "saying please quit the application".
This is the best way to do this
UIApplication *myapp = [UIApplication sharedApplication];
[myapp performSelector:#selector(suspend)];
Include this code where ever you need thats it. But still not recommended by apple
Developer apple link
There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. see link text
There's one non-recommended way that crashes the app:
[[UIApplication sharedApplication] sendAction:SIGKILL to:[UIApplication sharedApplication] from:self forEvent:nil];
The app will not close the proper way or save. It's more recommended to use a UIAlertView with no buttons to force the user to close the app.
exit(0) is not apple standard way to exit the app and apple highly discourages it.Though, sometimes it approves some application.Give proper UI to show if any functioning is not working or give suggestions regarding it to user.killing app programmatically is not right way.Let user Handle the exit on their own.