iPhone SDK Quitting - iphone

I have found many apps where you can press a button or something similar and the application will terminate and bring you back to the home screen. How would I do this?

exit(0);
this can exit the app .
again, the best way I think will be like as follows:
//#step invoke the normal routine applicationWillTerminate
if ([[UIApplication sharedApplication].delegate respondsToSelector:#selector(applicationWillTerminate:)])
{
[[UIApplication sharedApplication].delegate performSelector:#selector(applicationWillTerminate:) withObject:[UIApplication sharedApplication]];
}
//#step force quite app
kill(getpid(), SIGINT);
I got it from other post on the overflow :D

from http://www.iphonedevsdk.com/forum/iphone-sdk-development/6928-exit-application.html
[[UIApplication sharedApplication] terminateWithSuccess];

Related

Make a Call from UITableViewCell

I stuck with a problem.
In my tableView I got a cell with a phone number. I would like to click on the phone number and make a call.
I implemented the following in didSelectRowAtIndexPath:
NSString *cifra=#"tel://123456789";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra]];
NSLog(#"after call %#",cifra);
Unfortunatly it doesnt do anything. In my log it shows me my "after call ... " but it is not calling. No error, no log, no action :(
It works for me with opening a website or googleMaps, but not for calling.
Is there anything i can do?
Maybe a it is simple answer, but i really dont know what to do. Is there a different way to make a call?
I am using the iPhone Simulator. Is this the problem? But it should do a thing, shouldn't it? :)
Thanks for your help!
You can't make calls from the Simulator.
If you want to test making a phone call, run the app on your device, then press the cell to make a phone call on your actual device.
You can simulate the in-call status bar, but there is nothing actually happening when it comes to actual phone calls.
Hardware > Toggle In-Call Status Bar
Note that using [[UIApplication sharedApplication] openURL:SOMEPHONENUMBER]; does not trigger this event.
Tried this code to make a call
NSString *prefix = (#"tel://(972)818-32432");
UIApplication *app = [UIApplication sharedApplication];
NSString *dialThis = [NSString stringWithFormat:#"%#", prefix];
NSURL *url = [NSURL URLWithString:dialThis];
[app openURL:url];
On top of the answers mentioning you can't make calls from the simulator, cifra should be #"tel:123456789", the double slashes aren't needed.

call safari in iphone program

i am working on an application in which i needs to call safari when i click on a button.....
please tell me how to do this
should i create a new view for this ?
kindly help....
please also tell about importing messagebox and callmanager if possible.....
(not talking about sending msg or call from my app ...know that is not possible... i want to call inbuilt applications only) .
also wanto confirm that will my app close when i will call these inbuilt applications....
thanks....
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9016098909891"]];
You can use the above function to call from the iphone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
USe this to open safari and so on.. hope yo got the idea what exactly to do....
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms://9016098909891"]];
uSe the above to send SMS from iphone
hAPPY cODING....
If you call openURL with a general (for example not a youtube link) web page, then by default it will be opened through safari. However, your app will be terminated.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.yahoo.com"]];
Sorry, can't help about the messagebox.

after call end, relaunch the previous app in iphone

I can make a call from my app by use this APIs.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:XXXXXX"]];
I would like to return to my app where I left after the users ends the call. Is that possible?
Try this:
UIWebView *callingWebview;
[callingWebview loadRequest:[NSURLRequest requestWithURL:]];
no it's not possible

iPhone iOS 4: how do you go from background to foreground in objective-c

I am trying to make my application that is in the background come to the foreground after a call is disconnected. Here is the code:
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel:0123456789"]]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:0123456789"]];
} else {
// Could not make call
}
CTCallCenter *c=[[CTCallCenter alloc] init];
c.callEventHandler=^(CTCall* call){
if(call.callState == CTCallStateDisconnected) {
// code to make app return to the foreground
// I have tried calling applicationWillEnterForeground, but it didn't work
}
}
Please help
I am fairly certain you can't do it with a simple call. Maybe registering a URL handler my app:// and usinng openURL in the completion block could work, but that seems quite hacky.
Apple will not allow you to "come to the foreground" but you can use a local notification instead.
So for what you want to do you need to:
After starting the dial url you will get a 'applicationDidEnterBackground:' as your app is pushed to the background. You will need to start a background task or else you will not get the call state change.
When you get a call state change, create a local notification. If the user wants to "view" your application then you app will come to the foreground.
There is one problem with the above, if the phone call is longer than 10 min's then the background task will be terminated you will not get your call state change.

Restarting iPhone application after [UIApplication sharedApplication] openURL

As title says I'd like to know how to restart my iPhone app after doing this:
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"tel://0123456789"]]
It seems pretty simple as I saw many topics also talking about restoring the very state of the application when openURL is called, but I can't find how to simply restart the app when the calling is finished.
Is it supposed to be the default behavior? As for me, the iPhone opens Favorites after call is finished, I don't know why.
You can't. Starting an app is solely user's responsibility - which I consider a good thing.
check the discussion here: https://devforums.apple.com/message/128046#128046
create a UIWebView to load the phone url like this:
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
just use
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"telprompt://0123456789"]]
It will return to the app after call finished
You can't restart an app after a phone call, as your app has terminated and your code is no longer being run.
If you want to restart after the user visits a webpage, you can put a link with a custom scheme in that webpage, and register it with your app. The user can then tap the link to open your app again.