iphone - start an application at the end of a phone call - iphone

Is it possible to launch an application at the end of phone call or after sending SMS?

NO this is not at all possible. Because you cant get the event when the call is ended or message is sent. So theres no way you can open up the application.
Happy Coding...

I got this code from Apple site and it works perfectly:
- (IBAction) dialNumber:(id)sender{
NSString *aPhoneNo = [#"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ;
NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
}
else {
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:aPhoneNo]];
}

Looks like it might help ..
iPhone SDK: Launching an app after call ends

Related

Foursquare integration in iPhone

I am trying to do the FourSquare integration in iPhone..i couldn't found any good guidelines through Goggling.... Can any one suggest me the Good guidelines or URLs for FourSquare integration in iPhone..
Thanks
Here is the foursquare api link
Example of Foursquare integration link.
Further code for Foursquare integration
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Foursquare";
//check the authentication
if ([Foursquare2 isNeedToAuthorize]) {
//If needed show the webview
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
NSString *url = [NSString stringWithFormat:#"https://foursquare.com/oauth2/authenticate?display=touch&client_id=%#&response_type=code&redirect_uri=%#",OAUTH_KEY,REDIRECT_URL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[webView loadRequest:request];
[webView setDelegate:self];
[self.view addSubview:webView];
[webView release];
mTableView.hidden = YES;
}else{
//Show your view
mTableView.hidden = NO;
[Foursquare2 searchVenuesNearByLatitude:#"40.763" longitude:#"-73.990" accuracyLL:nil altitude:nil accuracyAlt:nil query:#"" limit:#"15" intent:#"" callback:^(BOOL success, id result){
if (success) {
tableData = [[FoursquareParser parseSearchVenuesResultsDictionary:(NSDictionary*)result] retain];
[mTableView reloadData];
}
}];
}
}

Making a call programmatically from iPhone app and returning back to the app after ending the call

I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.

WebView seems to be leaking according to instruments. GeneralBlock-56

Instruments is reporting a lot of leaks like :
GeneralBlock-56
GeneralBlock-8192
GeneralBlock-2048
GeneralBlock-24
GeneralBlock-32
GeneralBlock-8
GeneralBlock-16
This all happens when I open a class that just displays a UIWebView.
Here is the guts of the code from the class:
appDelegate = (DemoSAPAppDelegate *)[[UIApplication sharedApplication] delegate];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
aWebView.scalesPageToFit = YES;
[aWebView setBackgroundColor:[UIColor clearColor]];
[aWebView setOpaque:NO];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[[[aWebView subviews] lastObject] setScrollEnabled:YES];
[self.view addSubview:aWebView];
[aWebView release];
Am I doing something wrong here? The WebView is released there at the end.
Do I need to use something like an autoreleasepool?
Quite confused to see my app hemorrhage memory over this.
Is that on an actual device? Or the simulator? The frameworks the simulator uses leaks in many places; they are not as finely tuned as the device binaries. Always test on an actual device; the simulator, is after all, just a simulation.

Make a row in UITableView point to a URL

I have a table which lists out items I would to make each of the row in the table to point to a URL which is assigned to each item.
In your tableview delegate function didSelectRowAtIndexPath you can use this code to open a url in the Safari application.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSURL *url = [NSURL URLWithString:#"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url];
}
If you don't want to leave your app, you can open the url in a UIWebView.
UIWebView * wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
[self.view addSubview:wv]; // or push onto Navigation Stack
// if adding wv as subview, also need to add a back button to self.view to dismiss webview.
[wv loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString: myURLForSelectedRow]]];
[wv autorelease];
When a cell is selected, the -tableview:didSelectRowAtIndexPath: delegate method will be called. From there, assuming you have the url for each row, the following code will open the URL url in Safari.
NSURL *url = /* Assume this exists */;
if( [[UIApplication sharedApplication] canOpenURL:url] )
{
[[UIApplication sharedApplication] openURL: url];
}

Email app from another app

I want to start an email app from app on button pressed. But when I pressed the button nothing is happening !!!
code :
- (IBAction) startMail
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto:emailAdress?subject=testMail&body=its test mail."]];
}
any thing wrong in code ? Also button is properly set in IB.
Thanks..
If you want to compose an EMail inside your app, you should have a look at the MFMailComposeViewController reference to do so instead of calling a mailto: URL scheme.
Using the mailto URL won't work in the simulator as mail.app isn't installed on the simulator. It does work on device though.
You can use "MFMailComposeViewController" to send mail from your application.
Sample code-
MFMailComposeViewController *picker;
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *objSubject = [[NSString alloc] init];<br/>
NSString *emailBody = [[NSString alloc] init];
[picker setSubject:objSubject];
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
You must use the following delegate to check the status of mail sent or not
**-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
}**
Enjoy
Try this:
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
Here to, subject and body are NSString variables
Check this out, it's a better solution than directing your user out of the app;
How can I send mail from an iPhone application
NSString *url = [NSString stringWithString: #"mailto:foo#example.com?cc=bar#example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];