External google search link open in browser - ios

I want to open the google search link like 'https://www.google.co.in/#q=adam+scott' in sencha touch hybrid ios app. I tried to use var ref = window.open(url, '_blank','location=yes'); but it is not loading the page and if I change the _blank to _system it is loading the page but not showing done button to move to previous page.
Please let me know if some body has done it.

I think this is what you are looking for:
navigator.app.loadUrl('https://www.google.co.in/#q=adam+scott', { openExternal:true } );

open your MainViewController.m class and add this line of code before #end
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:#"http"] || [[url scheme] isEqualToString:#"https"]){
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
}

Related

Obj-C decidePolicyForNavigationAction not being triggered

decidePolicyForNavigationAction is not being triggered when the webview loads a new page. It works when everything is initially loaded but then never gets triggered after that.
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSLog(#"decidePolicyForNavigationActionnavigationAction.request.URL.absoluteString:%#|", navigationAction.request.URL.absoluteString);
if (kTestLocalHTML == 1) {
decisionHandler(WKNavigationActionPolicyAllow);
return;
}
NSURL *url = navigationAction.request.URL;
if (url != nil) {
//
// TODO: Trim the url string below as well?
// No, because this is being trimmed already in the AppManager methods related to web view URL
//
NSString *urlString = url.absoluteString;
WKNavigationType navType = navigationAction.navigationType;
//
// Display the club mobile native login page and log the user out
// if the webview is about to load the blazor login page URL
//
if ([urlString isEqualToString:[AppManager getMobileLoginUrl]]) {
self.appManager.userLoginDetails = nil;
[self displayLoginPage];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
//
// Check if link is tapped from webview and if URL string contains the
// prepended identifier within the JavaScript injection which can be found in
// "webViewDidFinishLoad" delegate method of webview
//
if (navType == WKNavigationTypeLinkActivated && [AppManager isWebViewURL_containsTargetBlank:urlString]) {
//
// Make sure to ignore the prepended identifier on the URL string
// before opening it on an external browser
//
NSInteger targetBlankIdentifierLength = kIdentifier_TargetBlank.length;
NSURL *url = [NSURL URLWithString:[urlString substringFromIndex:targetBlankIdentifierLength]];
[[UIApplication sharedApplication] openURL:url];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
//
// Check if url has custom scheme other than "http" & "https" (If is either one of the tags for Telephone "tel", Mail "mailto", SMS "sms", Web Calendar "webcal", etc.)
//
// Solution Reference: https://stackoverflow.com/questions/47040471/wkwebview-not-opening-custom-url-scheme-js-opens-custom-scheme-link-in-new-wind
// - (Answers of both "hstdt" & "mattblessed")
//
// NOTE: It seems loading telephone and mail links do not work when testing on an iOS simulator.
//
NSString *urlScheme = url.scheme;
BOOL isCustomURLscheme = ( ! [urlScheme isEqualToString:#"http"] && ! [urlScheme isEqualToString:#"https"]);
if (isCustomURLscheme) {
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
//
// Get reference to the current URL being requested so that if there
// will be failure in loading the webview, we have a reference to that URL.
//
self.currentUrlRequest = navigationAction.request;
// Check if web view URL contains a calendar file to download
if ([AppManager isWebViewURL_containsCalendarDownload:urlString]) {
//
// Download and process calendar file either from Events or Dining module
// and display "New Event" page where user can view its details, edit and save to device calendar
//
[self processCalendarFileAndDisplayEventPageWithURLrequest:self.currentUrlRequest];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
// Check if web view URL contains a PDF file attachment to download
else if ([AppManager isWebViewURL_containsPDFAttachmentDownload:urlString]) {
// Display document viewer page and pass few parameters for page customization (initial URL to load, navigation bar title)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:kStoryboardName bundle:nil];
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:kStoryboardID_OverlayBrowserNavigationController];
OverlayBrowserViewController *vcOverlay = (OverlayBrowserViewController *)[navigationController topViewController];
vcOverlay.initialURLtoLoad = urlString;
vcOverlay.navigationBarTitle = [self getPDFDocumentNameFromURLString:urlString];
[self presentViewController:navigationController animated:YES completion:nil];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
}
decisionHandler(WKNavigationActionPolicyAllow);
}
This function is supposed to trigger and detect if the webview is loading the web login page and if that is the case it will logout the user and instead show the apps native login page. However the function is never triggered after the main screen is loaded initially.
"Are you sure the web page is actually performing a redirect and is not a SPA like Angular which may not be updating the URL? Also how are you setting self.wkWebMain? – RunLoop"
Thanks for this, you were correct and the webpage was acting as an SPA which was the reason the function would call at first on the initial load but not after.

LiveSDK + iOS login: not redirecting back to the app after allowing permissions

I have imported liveSDK with pods, my app is set.
This is how I login in swift (I've implemented LiveAuthDelegate too):
var live = LiveConnectClient(clientId: ClientID, delegate: self)
live.login(self, scopes: Scopes, delegate: self)
I get the login and password screen, I sign in with my credentials.
I get the permissions view where I can say yes or no to the asked permissions
I click yes
I get blank page... instead of being redirected back to my app
Any ideas ?
please help
EDIT: i think i am redirected to some page like https://login.live.com/oauth20_desktop.srf?error=server_error&lc=1033 this site and its blank? what could be the reason ?
I tried logging the url in the LiveSDK, but its crashing the app on NSLog
#pragma mark UIWebViewDelegate methods
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
NSLog([url absoluteString]);
if ([[url absoluteString] hasPrefix: _endUrl])
{
[_delegate authDialogCompletedWithResponse:url];
}
// Always return YES to work around an issue on iOS 6 that returning NO may cause
// next Login request on UIWebView to hang.
return YES;
}
In the end i happened to add a retaint:
_liveConnectClientCore = [[[LiveConnectClientCore alloc] initWithClientId:clientId
scopes:[LiveAuthHelper normalizeScoers:scopes]
delegate:delegate
userState:userState] retain];

iOS web view with urlstartswith

if there is someone who can help me to create a simple iOS app , i need just the code
The app needs a WebView wich will load the following url http://www.applicationurl.com/?param=(udid)
The param udid needs to be static so it will never change
The app will have 1 Back button for the webview and 3 simple ifUrlStartsWith if's
if the link in webview is Click to Call it will call that phonenumber
if the link in webview is Apple Map's it will open the Apple maps to a static adress , the adress could be stored in NSSTRING mapadress=#"Romania Street Haleluia nr.2";
if the link in webview is Exit App it will automatically close the app
Can any one help me please ? i always get stuck at urlstartswith and the current url is not showing up.
The code i'm using
//
// ViewController.m
// Aqua Park President
//
// Created by Alex Bonta on 7/13/14.
// Copyright (c) 2014 Aqua President. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webView;
- (void)viewDidLoad
{
// GET THE PHONE UDID
NSString *udid=[[[UIDevice currentDevice] identifierForVendor] UUIDString];
udid=[udid substringToIndex:5];
// Loading the url adress with the param of the uinique id
NSString *string = [NSString stringWithFormat:#"http://app.aquapark-felix.ro/?email=%#",udid];
NSURL *url = [NSURL URLWithString:string];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
NSString *currentURL = webView.request.URL.absoluteString;
- (BOOL) webView;(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//Catching URLs and telling the app what to do
if ([[[request URL] scheme] isEqualToString:#"tel"]) {
NSLog((#"ASA"));
}
}
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have cleaned up your code as well as answering it. Please see the comments in the code for an explanation of the code and also please see the Apple URL Schemes Documentation. The Below code has been tested and works when you pass in a correct URL scheme such as
HTML for making phone call
1-408-555-5555
Natiave for making phone call
tel:1-408-555-5555
HTML for accessing maps app
Directions
Native for accessing maps app
http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino
If you haven't configured these properly it will not work. As you are coming from a website you will need the HTML versions.
//
// ViewController.m
// Aqua Park President
//
// Created by Alex Bonta on 7/13/14.
// Copyright (c) 2014 Aqua President. All rights reserved.
//
#import "ViewController.h"
#implementation ViewController
// This can be removed as it is done automcatically for you.
//#synthesize webView;
- (void)viewDidLoad
{
// A call to the super must come first.
[super viewDidLoad];
// Construct a url request with the UUID string and pass it to the _webView
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://app.aquapark-felix.ro/?email=%#",[[[[UIDevice currentDevice] identifierForVendor] UUIDString] substringToIndex:5]]]]];
}
- (BOOL) webView;(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Check whether the URL scheme is of "tel"
// "loc" will not open the apple maps app this code is done so it will.
if([request.URL.scheme isEqualToString:#"tel"] || [request.URL.absoluteString hasPrefix:#"http://maps.apple.com/?q"]) {
// We need to make sure we can actually open the urls that have been passed in.
// We do this for two reason 1) if we couldn't it would be a bad user experience
// and 2) you can't make calls on a iPod.
if([[UIApplication sharedApplication] canOpenURL:request.URL]) {
// Yes we can make a phone call so lets make it.
// Based on your number being formatted correctly if it's not then it will not work.
[[UIApplication sharedApplication] openURL:request.URL];
}
// If all else fails and we can't open the url just return no.
// I would recommend a UIAlertView here to tell the user.
return NO;
}
// As for exiting the app don't do this at all.
// Every other URL just return YES and continue with the Request.
return YES;
}
#end
If you're trying to get the URL Scheme (http, loc, tel etc)
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//Catching URLs and telling the app what to do
if ([[[request URL] scheme] isEqualToString:#"tel"]) {
// Code
return NO;
}
return YES;
}
And so on for your other schemes.
This needs to go outside of viewDidload. See below.
// ViewController.m
// Aqua Park President
//
// Created by Alex Bonta on 7/13/14.
// Copyright (c) 2014 Aqua President. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webView;
- (void)viewDidLoad
{
// GET THE PHONE UDID
NSString *udid=[[[UIDevice currentDevice] identifierForVendor] UUIDString];
udid=[udid substringToIndex:5];
// Loading the url adress with the param of the uinique id
NSString *string = [NSString stringWithFormat:#"http://app.aquapark-felix.ro/?email=%#",udid];
NSURL *url = [NSURL URLWithString:string];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
NSString *currentURL = webView.request.URL.absoluteString;
[super viewDidLoad];
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//Catching URLs and telling the app what to do
if ([[[request URL] scheme] isEqualToString:#"tel"]) {
NSLog((#"ASA"));
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

Delegate to know when phone call ends which was initiated by app

I have a code which places a phone call using below code :
// Make a call to given phone number
- (void)callPhoneNumber:(NSString *)phoneNumber
{
if (!self.webview)
self.webview = [[UIWebView alloc] init];
self.webview.delegate = self;
// Remove non-digits from phone number
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:#""];
// Make a call
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phoneNumber]];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:self.webview];
}
This makes a call. What I want is, I want to know when user ends a call. I have to perform an operation when user ends a call. Is there any way for it?
What I tried is, I set delegate of webview to current controller. But none of the delegate methods is called.
- (void)webViewDidStartLoad:(UIWebView *)webView
{
DLog(#"Start Loading");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
DLog(#"Finish Loading");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
DLog(#"Did fail with error : %#", error);
}
I don't know if you need this info but I use webview so that when phone call is made, flow remains within the app and on call end, app screen is displayed rather than user manually coming to app from native contact app.
CoreTelephony framework has a CTCallCenter Class with callEventHandler property.
#property (nonatomic, copy) void (^callEventHandler)(CTCall*);
You will have to define a handler block in your application and assign it to this property.
If your application is active when a call event takes place, the system dispatches the event to your handler immediately when call state changes. Refer apple documents found here.
I used below code to get notified of call events.
// Create CTCallCenter object
callCenter = [[CTCallCenter alloc] init];
// Assign event handler. This will be called on each call event
self.callCenter.callEventHandler = ^(CTCall* call) {
// If call ended
if (call.callState == CTCallStateDisconnected)
{
NSLog(#"Call ended.");
}
};
For other call states check out Call States. For more info on CTCallCenter look at Apple doc for CTCallCenter.
You should be implementing this delegate method of UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
on end call operation your webview will notify this delegate method about your action perform and you can handle it in there for example
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked )
{
NSURL *url = [request URL];
NSLog(#"URL ===== %#",url);
// you can check your end call operation URL and handle it accordingly
if ([[url absoluteString] rangeOfString:#"#"].location == NSNotFound)
{
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
//return NO;
}
return YES;
}

Phonegap iOS: InAppBrowser opens but clicking on link sometimes does not open the page and event "falls through" to main webView

I'm developing an iOS app using phonegap and HTML5.
After launchImage in app, I open InAppBrowser, which opens promptly.
But, tapping on links in it sometimes does not open the desired page and event "falls through" to main webView.
i.e., InAppBrowser is closed on tapping the link.
Please do help me out as I'm stuck with this for the past two days.
Try this one
Put this code in your MainViewController.m before #end tag
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:#"http"] || [[url scheme] isEqualToString:#"https"]){
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
}
Resolved this issue by bypassing the error code. It is a bit of dirty workaround but couldn't help it. In "CDVInAppBrowser.m", modified as below and InAppBrowser loads my url successfully.
- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
//By passing error code
if(error.code == -999)
return;
// log fail message, stop spinner, update back/forward
NSLog(#"webView:didFailLoadWithError - %i: %#", error.code, [error localizedDescription]);
self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward;
[self.spinner stopAnimating];
self.addressLabel.text = NSLocalizedString(#"Load Error", nil);
[self.navigationDelegate webView:theWebView didFailLoadWithError:error];
}

Resources