Open and install iOS app from UIwebview - ios

I have an apps link using link maker from AppStore . I have a UIWebView in my app and I am trying to load the link in UIWebView but each time I load that link it opens the inbuilt AppStore instead of showing the content in the UIWebView. I want to open the link in UIWebView instead of opening the inbuilt iOS AppStore.
This what i tried
- (void)viewDidLoad
{
str = #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa";
str = [NSString stringWithFormat:#"%#/wa/viewContentsUserReviews?", str];
str = [NSString stringWithFormat:#"%#type=Purple+Software&id=", str];
// Here is the app id from itunesconnect
str = [NSString stringWithFormat:#"%#289382458", str];
[webOpenApp loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
}
-(BOOL) webView:(UIWebView *)inWeb
shouldStartLoadWithRequest:(NSURLRequest *)inRequest
navigationType:(UIWebViewNavigationType)inType
{
if (inType == UIWebViewNavigationTypeOther) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
return NO;
}
return YES;
}

The itms-apps:// is an special protocol that when iOS system read this it will launch the App Store to show that app. Apparently this is not what you want.
You should build the UI yourself to display the information of the app. And when user click the buy button you have to redirect user to App Store. Because App Store is the only place user could buy and download an app.

Related

Xcode WebView. Open target="_blank" links in Safari

I have a small app for iOS that uses WebView. I need links that contain target = "_blank" to open in Safari
I found a solution. But it does't work for me.
https://stackoverflow.com/a/15048074/4489534
All links are now opened in Safari, and all links containing "?openInSafari = true" too. But external(downloadable) files like PDF open in WebView.
I can't understand why the condition doesn't work
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *url = [request URL];
NSString *string = [url query];
if ([string rangeOfString: #"openInSafari=true"].location != NSNotFound){
[[UIApplication sharedApplication] openURL: url];
NSLog(#"Open in Safari");
return NO;
}
}
NSLog(#"Open in WebView");
return YES;
}
EDITED
When i click to link containing "?openInSafari = true", i get "Open in Safari openInSafari=true"
When i click to normal link, i get "Open in Safari (null)"
When i click to downloadable link to PDF file, i get "Open in WebView product_id=50&download_id=21"
When i click to direct link to PDF file, i get "Open in Safari (null)"

Link from iOS app to website

I am looking to link my iOS app to my website. I want the link to open the safari web browser. Currently the link goes to the website but stays in the app.
Here is what I am using:
<a onclick="window.location.href='http://www.website.com/folder/page.php';">Contact</a>
Any suggestions?
To open a webpage in device's browse, use following code
NSURL *strURL = [[NSURL alloc] initWithString:#"http://www.website.com/folder/page.php"];
if ([[UIApplication sharedApplication] canOpenURL:strURL]) {
[[UIApplication sharedApplication] openURL:strURL];
} else {
NSLog(#"Cann't open url : %#",strURL);
}

UIDocumentInteractionControllerDelegate methods not called when open system apps like Mail, Messages, Twitter or Facebook

I'm using UIDocumentInteractionController to share a picture in Instagram and other apps like Whatsapp, Google Drive, Dropbox... (as many of you already know the Instagram pictures has the ".ig" or ".igo" file extensions). If I share the picture.ig in other apps instead of Instagram then the pictures appears like a file and not like a picture. So I implement the delegate method:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
if (![application isEqualToString:#"com.burbn.instagram"]) {
NSURL *newPath;
NSString *oldPathStr = [controller.URL absoluteString];
NSString *newPathStr = [oldPathStr stringByReplacingOccurrencesOfString:#"ig" withString:#"jpg"];
newPath = [NSURL URLWithString:newPathStr];
controller.URL = newPath;
controller.UTI = #"public.jpeg";
}}
That way if the app is not Instagram I could share the other version of the file in jpg (I have both .ig and .jpg versions stored in disk).
But, the problem is that DocumentInteractionController doesn't call this delegate method when I am trying to share the picture with the system apps like Mail, Messages, Twitter or Facebook so I could't use the jpg URL and people receive a .ig file in their iPhones or laptops that they don't know how to open. If I try to open other apps like Whatsapp there isn't any problem and the delegate is called.
Do you know how could I take control of this before the system open the mail composer, message composer or social composer?
Thank you so much.
I find a solution. First of all I configure a UIDocumentInteractionController
- (void)setupDocumentControllerWithURL:(NSURL *)url {
if (self.docInteractionController == nil) {
self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docInteractionController.delegate = self;
}
else {
self.docInteractionController.URL = url;
}
}
Then open the Instagram .ig file with the docInteractionController, if you open the .jpg instead of the .ig file, then the Instagram app wouldn't appear in the "Open In App" menu
//share the Instagram .ig picture fileURL
[self setupDocumentControllerWithURL:fileURL];
[self.docInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
Then you have to change the URL inside a delegate method to allow the system apps to share the .jpg instead a file with .ig extension (only Instagram and a few other apps recognize the .ig file as a picture
- (void)documentInteractionControllerWillPresentOptionsMenu:(UIDocumentInteractionController *)controller {
NSURL *theUrl = controller.URL;
NSString *theInstagramPath = theUrl.path;
NSString *jpgPath = [theInstagramPath stringByReplacingOccurrencesOfString:#"ig" withString:#"jpg"];
NSURL *jpgURL = [NSURL fileURLWithPath:jpgPath];
controller.URL = jpgURL;
}
After that Mail app, Messages, Twitter and Facebook (and non system apps) will open the file as a jpg. But we have to change the url again if we want to open the file inside Instagram:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
//Check if the app that is calling is Instagram
if ([application isEqualToString:#"com.burbn.instagram"]) {
NSURL *newPath;
NSString *oldPathStr = [controller.URL absoluteString];
NSString *newPathStr = [oldPathStr stringByReplacingOccurrencesOfString:#"jpg" withString:#"ig"];
newPath = [NSURL URLWithString:newPathStr];
controller.URL = newPath;
}}
And that's all. It seems that the willBeginSendingToApplication: is not being called if you select a system app in the menu.
you have missed to set the delegate of your UIDocumentInteractionController instance.
after creation of UIDocumentInteractionController do like this
YourUIDocumentInteractionControllerObject.delegate = ObjectWhichHaswillBeginSendingToApplicationMethodImplementation;

How to make html link within NSString?

I have NSString as follows
NSString *textOutStations = [NSString stringWithFormat:#"Hello Everyone. Please check out website:<br> http://www.google.com/</br>"];
I want to show google.com as below in URL, as I will load this in UIWebView.
www.google.com
So, whenever user click it, It must open Safari in iPhone.
NSString *textOutStations = [NSString stringWithFormat:#"Hello Everyone. Please check out website:<br> http://www.google.com/"];
[self.webView loadHTMLString:textOutStations baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
Then in UIWebView delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Opening safari
[[UIApplication sharedApplication] openURL:request.URL];
....
}
Try this one
NSString *textOutStations = #"<html><head><title></title></head><body><div> Hello Everyone. Please check out website:<br/> http://www.google.com/ </div></body></html>";
[self.webView loadHTMLString:textOutStations baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
This will help you......
You can not specify a URL with in a string and have it be clickable, this type of functionality is dependant on the object to which is using it, aka, UITextView UITextField UILabel UIWebView etc,
A UIWebview will show your url with in the webview it will not open the link in safari. IF you want to load it in ui web view, it's already ansered above, if you want to open it in safari, you have to do
[[UIAplication sharedApplication] openUrl:urlObject];
if you want to open it to be text with in a UITextView i would suggest this other stack overflow link here
I checked the link option in Attribute Inspector of UIWebView and it detected the link.
Method to OPEN in SAFARI...
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}

Open Facebook url in Safari instead of native app

is there any way to open Facebook url (ex. http://www.facebook.com/facebook) in Safari instead of native app? I'm tried to do this:
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/facebook"];
[[UIApplication sharedApplication] openURL:url];
but iOS automatically launch native client (of course if it's installed) if you try to open url with in facebook domain. thanks.
Ok, I think I found answer, you must replace "www.facebook.com" with "facebook.com" in url.
Something like this:
NSString *facebookUrlString = #"http://www.facebook.com/facebook";
if ([[facebookUrlString pathComponents] count] > 0) {
if ([[facebookUrlString pathComponents][1] isEqualToString:#"www.facebook.com"]) {
NSMutableArray *pathComponents = [[facebookUrlString pathComponents] mutableCopy];
[pathComponents replaceObjectAtIndex:1 withObject:#"facebook.com"];
facebookUrlString = [NSString pathWithComponents:pathComponents];
}
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookUrlString]];
Copy link to the messenger app and send to yourself. Open the link on messenger app and click on share and will apear open with facebook app

Resources