Event/Method triggered when call triggered from WebView ends in IPhone? - iphone

I am triggering a phone call through a UIWebView, so that when the call ends, the user is returned directly to my app, via the following code:
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:number-to-call"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
When it returns control back to my App I'd like to execute some code, but I am unable to determine what if any method the OS is calling when it returns to my App after the call ends? ViewWill, ViewDid etc never get called when control returns.
What if anything gets called when the call ends and control returns to the webview/app?

UIWebview Class has some delegate founctions.webview call these founctions when start loading and finish loading request and so on. I have poor English,I wish you can understand me.if I misread your question and my answer isn't what you want,please forgive me.

Related

Validate if call was made after telprompt

I want to validate if user tapped on Call button or Cancel button after telprompt
Current code:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", [personDetails valueForKey:#"phone"]]];
[[UIApplication sharedApplication] openURL:url];
How can I do so?
First telprompt: is not a documented URL schema and should not be used. Since Apple can change the way it used at any moment.
Second since data is passed back to your app, you will not be able to detect a if call was made. You might be able to detect if you use the CoreTelephony. But getting this to work require your app to run in the background and you might have to misuse some background mode for this which will make Apple reject your app.
Can you explain why you want to detect if there was a call made?
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(called:) name:#"UIApplicationSuspendedNotification" object:nil];
-(void)called:(NSNotification *) notification
{
NSLog(#"Tapped Call button");
}
if Call button was tapped then application will be terminated and go into background so just add an observer for the UIApplicationSuspendedNotification notification.
For my case, I used tel:// instead of using telprompt:// and make my own UIAlertView. This way you could detect if the call option is tapped from the UIAlertView's delegate.

Overriding viewDidAppear and have it load specific URL not OK?

I'm reviewing someone else's code and noticed a web form gets refreshed every time you attach an image(click 'add image', find and choose image, return to form, form goes blank). And, it's because the url gets reloaded. In tracking this issue down I noticed that the original dev overrode the viewDidAppear instance method in WebViewController like so:
- (void) viewDidAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:self.defaultUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
}
Apple's documentation says
You can override this method to perform additional tasks associated with presenting the view. If you override this method, you must call super at some point in your implementation.
I see super isn't called and I think putting in an NSURLRequest is not good practice. I removed the code, added the URL call a button action and all's well so this is mostly a stylistic/academic question.
Do you agree that loadRequest shouldn't be in there? Thanks for your help.
Why shouldnt it be there? loadRequest does its work asynchronously on another thread, so it doesn't block the main thread.
Connects to a given URL by initiating an asynchronous client request.
If it behaves the intended way, is for you to decide.
(Oh and yeah, you should call super in viewDidAppear)

Executing Code after programmatically making a phone call

How can you execute code after the phone call is made? My app makes a phone call with the following code:
- (void)callTelURL:(NSURL *)url
{
UIWebView *webview = [[UIWebView alloc] init];
[self.view addSubview:webview];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
[webview release];
}
I immediately get applicationWillResignActive, applicationDidBecomeActive and applicationDidEnterBackground but I never get applicationWillEnterForeground or applicationDidBecomeActive once the phone call has completed and I am back in my application. Is there something I can do to be notified when I have returned from my call so I can execute some code?
You won't get a call to applicationWillEnterForeground if your app is in the foreground when a call comes in and then the call is dismissed.
http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
So execute the code in applicationDidBecomeActive but only when the preceeding call was applicationWillresignActive.
P.S.
Just because your app gets a applicationWillResignActive then applicationDidBecomeActive does not necessarily mean you got a phone call, other things could cause this too. So you cannot rely on this if you want to execute code after only a phone call has caused this behaviour and nothing else

How do you create and manage a UIWebView object entirely in code?

I'm adding a UIWebView to my iOS App and I'd like it to open in response to a button getting clicked (so this code is going to be written in one of the button's event handler).
How can I create this UIWebView dynamically in code, position it to cover the entire screen and respond to events (e.g. to UIWEbView's shouldStartLoadWithRequest function so that the UIWebView can ask the native code to close the UIWebView).
I'd specifically like to avoid having to create stuff in Interface-Builder and it would be great if this could be reduced to several lines of code that could be later copy-pasted into other projects easily.
Simple:
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.delegate = self;
[self.view addSubview:webView];
You just need to implement the WebViewDelegate's method in the controller, that you are making the delegate of the UIWebView.

Put a link on home screen of my app and connect it to WebView

In my app i want to put my website's url on home screen and on clicking on it i want it to be open as a WebView.
How should i go for this.
Thanks,
Previous commenter is incorrect. You can open any hyperlink either externally with Safari or internally with a UIWebView.
Add a UIWebViewController to your project. Then, instantiate an instance of a the UIWebViewController that will be shown inside your app--you'll do this by declaring a property & synthesizing it within your main view controller (which will need to be declared as a UIWebViewDelegate), such as:
#interface MyMainViewController: UIViewController <UIWebViewDelegate> {
// Your implementation code here
}
When a user taps the button (assuming you make it a button, rather than just a text hyperlink), you instruct your app to add the UIWebView to the view stack, loading the correct link. You'll want to either do this within a modal view or within a navigation stack so your users can get back out of the web view, of course.
In your MyMainViewController implementation file, something like this:
-(void) showWebView {
// NOTE: I have not tested this, just prototyping
// off the top of my head
UIWebView *myWebView = [[UIWebView alloc] init];
myWebView.delegate = self;
NSURL *homeUrl = [[NSURL alloc] initWithString:#"http://example.com"];
NSURLRequest *homeRequest = [NSURLRequest requestWithURL:homeURL];
[myWebView loadRequest:homeRequest];
[self.presentModalViewController: myWebView animated:YES];
// Don't forget to release objects when you're done
[myWebView release]; // etc.
}
Now, this is off the top of my head from what I know and have done. But I hope you get the general idea. I offer no warranty of any kind here, but do guarantee this is entirely possible with minimal headache. If you get stuck, check out the developer references for UIWebView. Apple's docs are top-notch & show great examples to get you up and running quickly.
Best.