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;
}
Related
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
}
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.
My iOS app has a login page that is set up in a UIWebView. It also has a Facebook and G+ login. I can get the normal login screen to work, alright. But I am having problems when I do that with Facebook and G+. I am assuming that the reason is the New Window that pops up with the button click.
Is there any way that I can handle this without resorting to Manual Login?
It would be much easier to use native Facebook and G+ login. What you are trying to accomplish is much more complex than using native logins.
If you really, for some reason, must do it in a UIWebView, you would have to implement some strategy like this:
override -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method of UIWebViewDelegate protocol.
in your implementation, you should open the login interface in another modal UIWebView and handle login events there, and on the dismissal of that modal view, if login was successful continue with the app flow.
That would look something like this:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
//for facebook login
if ([[url absoluteString] containsString:#"m.facebook.com"] && [[url absoluteString] containsString:#"login"]) {
// instantiate and present new modal UIViewController containing UIWebView that loads the url.
return NO;
}
//for G+ something similar
return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
Then, the modal viewControllers for login would also have to implement the logic of how to handle the possible login events, and dismiss itself on success, which would be very complex.
The first webView would than also have to know when the modal is dismissed (can be done with protocol or some other way), and then check the login status, and proceed if successful.
So, as I said, it would be best if you used the native logins.
In my iOS app I have to have some native code and some web code. I am having a little difficulty integrating the navigation of the two.
For iOS I am using an embedded UINavigationController. In the web app I am using a single page application control with the Application Page doing the navigation through the web pages.
Here is the problem. On the first web page I suppress the navigation, as I want to use the iOS navigation there (to go back to from the main menu). A user taps the a list entry and the 2nd web page appears. Here I want to do the opposite - suppress the iOS Navigation but show the web navigation.
So I use the method shouldStartLoadingWithRequest to control whether or not to show the native UINavigation Controller. [method below]
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = [url absoluteString];
if ([urlString
isEqual:
#"https://myURL.xsp"] ||
[urlString isEqual:#"https://myURL.xsp/"]) {
[self.navigationController setNavigationBarHidden:FALSE animated:YES];
} else {
[self.navigationController setNavigationBarHidden:TRUE animated:YES];
}
return YES;
}
My problem is that when a user taps the web navigation to go back to the first view, the event does not fire again (as I am in the uiWebView I assume and so nothing in iOS has changed) and so I lose the native navigation. What I think I need is a way to fire off this method if the uiView changes?
Or is there a better way to handle this?
I am developing a ipad application in that i need to include facebook page like button. I have loaded the button using iframe in webview, when user clicked on the button if they already sigh in just count should increment or decrement else pop up will ask them to login first. once they logged in then increment the count automatically.
Any sample for code to do step by step.
Here is my webview like button code
NSString *likeButtonIframe = #"<iframe src='http://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&width=292&connections=0&stream=false&header=false&height=62' scrolling='no' frameborder=0' style='border:none; overflow:hidden; width:282px; height:62px;' allowTransparency='true'></iframe>";
NSString *likeButtonHtml = [NSString stringWithFormat:#"<HTML><BODY>%#</BODY></HTML>", likeButtonIframe];
[_webView loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:#""]];
Also i have tried before shows like i will ask him to login first then display the like button and ask them to like.
I used UIWebView's delegate method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
to detect when user does not have active session.
Here is my sample code: https://github.com/gneil90/facebook-likebox-ios-login
As per Facebook you should not have a like button in the app, that is to avoid spam likes.
Even through we can implement it using iFrame & UIWebView.
RayWinderlich has a great tutorial for this Facebook Like Button in iOS app.
Follow this link to generate a Facebook like frame for your page.
And use accordingly in your app, one limitation is that if user is not logged in it shows a login screen within it. So if your webView is small, it will be issue. Check out the sample from tutorial, and implement as per your requirements.