ipad app opens browser in the background - objective-c

Im using the openURL command to send an SMS, but it opens the safari,
can I send the command so it opens in the background??
ie, the user dont see the browser opening or the message that it gives, and stays in the app,
NSURL *url = [NSURL URLWithString: #"https://smsgw.exetel.com.au/sendsms/api_sms.php?username=xxx&password=xx&mobilenumber=0xxx&message=xxr&sender=mk&messagetype=Text&referencenumber=04"];
[[UIApplication sharedApplication] openURL: url];
Thank you

You can't have Safari open a URL for you in the background. But supposing you just want to request the URL and ignore whatever comes back, you could try:
NSURL *url = [NSURL urlWithString:#"...whatever..."];
NSURLRequest *request = [NSURLRequest requestWithURL:url delegate:nil];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request];
[connection start];

You can do this be creating a UIWebView inside your app, and calling loadRequest: on the instance, like this:
UIWebView *webView = [[UIWebView alloc] init];
webView.delegate = self;
NSURL *url = [NSURL URLWithString: #"https://smsgw.exetel.com.au/sendsms/api_sms.php?username=xxx&password=xx&mobilenumber=0xxx&message=xxr&sender=mk&messagetype=Text&referencenumber=04"];
NSUrlRequest *request = [[NSUrlRequest alloc] initWithURL:url];
[webView loadRequest:request];
This will load the URL inside the app, without sending you over to Mobile Safari. The benefit of this method over NSUrlConnection is that if you conform to the UIWebViewDelegate protocol and implement webViewDidFinishLoad: in your delegate class, you can see if the call succeeded or not.

Related

UITextView clickable url opens after terminating app

I am using datadetectortypes with my UITextView to be able to detect the links and navigate to the page. but the app is terminated and link opens with default safari after terminating the app. Is there any way to open the link within the application?
You can do that if you have web view
for example
NSString *urlAddress = #"http://myurl.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[myWebView loadRequest:requestObj];

going for the next youtube video in my iphone app

i'm developing an iphone app which can play youtube links using a web view
Every things fine. but except it goes to the next video automatically. is thr any way to stop this.
Here is my code.
NSString *urlAddress = #"http://www.youtube.com/embed/wh0ZK5QJMWk"; //http://www.youtube.com/embed/wh0ZK5QJMWk
NSURL *url = [[[NSURL alloc] initWithString:urlAddress] autorelease];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
Thanks

Return to my App after make a call

After my app make a call i would like to return to my app. When user hit "End" in call screen now he always see phone app. How to force app to return to my original app?
I make a call using:
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL]];
Try this.......
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", phoneNumber]
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can use the following code to get back to your app after making a call from your app
NSURL *url = [NSURL URLWithString:#"telprompt://phone number"];
[[UIApplication sharedApplication] openURL:url];
There's no way to do that without jailbreaking.

How to stop UIWebView loading immediately

As ios documentation says, [webView stopLoading] method should be used in order to stop webview load task.
As far as I see, this methods runs asynchronously, and does NOT stop currently processing load request immediately.
However, I need a method which will force webview to immediately stop ongoing task, because loading part blocks the main thread, which could result in flicks on animations.
So, is there a way to succeed this?
This worked for me.
if (webText && webText.loading){
[webText stopLoading];
}
webText.delegate=nil;
NSURL *url = [NSURL URLWithString:#""];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webText loadRequest:requestObj];
Don't use the UIWebView to download your html document directly.
Use async download mechanism like ASIHTTPRequest to get your html downloaded by a background thread.
When you get the requestFinished with a content of your html then give it to the UIWebView.
Example from the ASIHTTPRequest's page how to create an asynchronous request:
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
} 
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
 
// Use when fetching binary data
NSData *responseData = [request responseData];
}  
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
Use the responseString to your UIWebView's loadHTMLString method's parameter:
UIWebView *webView = [[UIWebView alloc] init];
[webView loadHTMLString:responseString baseURL:[NSURL URLWithString:#"Your original URL string"]];

passing a NSArray to NSURLRequest

I would like to pass a NSArray containing NSstrings to NSURLRequest, is it possible ? I'm not quite sure how to approach this, I'm getting it to work fine with just one URL but I can't seem to be able to pass an Array or urls . Any ideas ?
This is the code I'm using which is obviously wrong calling url1, I would like to call an array instead :
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
NSString *url1 = #"http://www.apple.com/";
NSString *url2 = #"http://www.google.com/";
urls = [[NSArray alloc] initWithObjects:url1,url2,nil];
NSURL *url = [NSURL URLWithString:url1];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Thanks !
So you want to load multiple webpages, right?
urls = [[NSArray alloc] initwithObjects:url1, url2, nil];
for (NSURL *url in urls) {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[webView loadRequest:request];
}
However, I'm not sure why you would want to do this? This may send a request to url1, but will instantly cancel that request and start loading url2.