ios web view accessing the camera - ios

Any body have idea, how to access the camera through a web view app in iOS?
Currently using Xcode 9 swift. but am willing to change the complete coding, if needed.
At the moment the WKWebview is being used.
Refer to this link to see my coding. "iOS web view application accessing the camera objc" thank you.

you can open camera on changing url.
when your URL will change below method will call, you can write code for open camera inside function
// this is delegate method called while changing url.
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//Code for camera after checking url
}

Related

iOS web view delegate methods are not getting called on Webpage navigation

Can not catch when web view change it's url without loading the page.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
This delegate method is getting called when loading the webpage for the first time.But after that if the webpage navigate on clicking of a button none of the delegate methods is getting called.If I load the page in browser I can see the URL change. Webpage is using History.pushState to change the URL.

iOS UIWebView popup blocker issue

In iOS, the default behavior when I open my webpage is that after login it opens the next page in a new window. But now when I open it in iOS webview, it does not open the next page. I google about it, and the cause seems to be the popup blocker. So, is there any simple way to disable the popup blocker in the iOS webview?
The webpage might have a redirection that you are not handling properly.
You may first want to use webView:didFailNavigation:withError: or webView:didFailProvisionalNavigation:withError: to get some reasons or clues. And you can try to debug webView:decidePolicyForNavigationAction:decisionHandler: to see whether you are allowing the navigation.
If the redirection somehow generates an about:blank page in the transition, you could try to use UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType: and returns a YES if request.URL.absoluteString is indeed about:blank, for example:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString isEqualToString:#"about:blank"]) {
return YES;
}
return NO;
}
BTW, you also can try to use Safari to debug webViews in your simulator. For instance, try document.location in your inspector to see what actually is the URL when the page doesn't open.

Flurry Analytics in a WebView in iOS

In my iOS Application I want to use Flurry analytics. On one of the application's screen there is UIWebView. And the site is on the server but not in the code of App. And every time when I loading that screen, information going from the server to my screen and everything is OK. There is a lot of buttons on my WebView and I want track them when they are pressed. I read about how to implement flurry analytics into the code of App if the buttons are in the code of App, but if the buttons are on the side of server(html/css/JS) I can't understand how can I track events from the UIWebView over the App to Flurry.
Flurry is writing this:
Can I track Events (e.g. pressing of a button) with Flurry Analytics if my app is a wrapper to my mobile website? The actions take place on the site server that the app is wrapping.
Yes, you can track these Events. If the action you want to track (e.g. button pressing) exists in the app code, then simply log an Event on the app side. If the button exists on the mobile webpage shown in a Web View, you will need to inject a Javascript function that will fire off an additional custom URL when the button is pressed. This URL will have a custom scheme, for example, “myapp://buttonclicked”. Then in the app code, you will need to capture that URL before your Web View fires it. When you see that the URL is your specified URL (“myapp://...”), you can log an Event on the app side.
There are several ways to capture the custom URL before it is loaded by the Web View. In iOS you would need to implement the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType:. On Android, you could implement a WebViewClient with the shouldOverrideUrlLoading method.
you can easily catch webview events through a delegate method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
bellow is that sample code, I used in on of my application:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if([[[request URL] absoluteString] rangeOfString:#"payment_successful_mobile.php"].location != NSNotFound)
return YES;
if([[[request URL] absoluteString] rangeOfString:#"index.php?file=c-my_campaingns"].location != NSNotFound)
{
[self onClickBackButton:nil];
return NO;
}
if([[[request URL] absoluteString] rangeOfString:#"Timeout"].location != NSNotFound)
{
[self performSelectorOnMainThread:#selector(displayTimeOutMessage) withObject:nil waitUntilDone:NO];
return NO;
}
return YES;
}

UIWebView not working first time in iOS 9

I have a UIWebView, whose delegate is set in viewDidLoad and then a URL is passed to it. This screen is loaded once the app launches. The webviewdoesn't load the URL and the delegate method (given below) is not called
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
There is a button on the same screen. When i press that after app launches. The same Web view loads.
Please tell me why my UIWebview is not loading for the first time?
It happens only in iOS 9. In iOS 8, it works perfectly.
Add below key in you .plist and try.

Intercepting a click in a UIWebView on iOS

I need to intercept a click on a UIWebView on a video pre-roll advertisement and have this displayed in a new popup window instead of in the UIWebView which is quite small on the screen.
The issue is that I don't know what the URLs that are being clicked and also that these clicks are processed via Javascript on the page as well. There would also be Javascript reporting/tracking calls going out from the UIWebView in the background.
Is there anyway to detect that the UIWebView is opening a new page and instead of displaying that in place it get's displayed in a popup?
Great question. All you will have to do is implement the UIWebViewDelegate protocols.
This method:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
is likely the one you will use to detect all events happening within the UIWebView.

Resources