safari link is not open in If www is missing iOS - ios

I Referred a many links related to this issue,But I cannot able to find the answer.I am getting a dynamic url in my app...If the url contains http://www then it opens the link,If www is not present then this error occurs.Any Help on this.
I am using this code,
NSString *selectedurl=[self.SelectedItem objectForKey:#"url"];
selectedurl=[selectedurl stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSURL *url=[NSURL URLWithString:selectedurl];
if (url.scheme.length == 0)
{
selectedurl = [#"http://" stringByAppendingString:selectedurl];
url = [[NSURL alloc] initWithString:selectedurl];
}
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:selectedurl]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:selectedurl]];
}

only the URL will start in www your page does not open, you need to append thehttp:` in front of the string, so try this
NSString *sentence = #"www.google.com";
NSString *searchWord = #"http";
if ([sentence rangeOfString: searchWord].location != NSNotFound) {
NSLog(#"Yes , the search word is available");
}else
{
// add the http in front of www using stringWithFormat
}
or the alternate way
NSString *string = #"www.google.com";
if ([string containsString:#"http"]) {
NSLog(#"string contains http..!");
} else {
NSLog(#"string does not contain http...!");
}
choice-2
I think what you are searching for is Universal Links. Check this documentation for it here. It's pretty simple and straight forward. And here is a step by step explanation of how to support them. And afterwards, you can validate your own custom universal links here or hereenter link description here

Related

Open apple maps on ios 8 and above not working

Im trying to create an application which will open apple maps located in iOS device with given source and destination address.
NSString* addr = [NSString stringWithFormat: #"http://maps.apple.com/?daddr=%#&saddr=%#",[_fromTextfield.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]],[_toTextfield.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];
addr=[addr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:addr];
if ([[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
But canOpenURL is not working ! It always returns NO.
I have added
"LSApplicationQueriesSchemes
urlscheme
urlscheme2
urlscheme3
urlscheme4
"
in Info.plist file.
Try below coding.it works perfectly.
NSString* addr = [NSString stringWithFormat: #"http://maps.apple.com/?daddr=%#&saddr=%#",#"Lacock" ,#"Avebury"];
NSURL* url = [NSURL URLWithString:addr];
if ([[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
If error is
"This app is not allowed to query for scheme whatsapp"
1) Check Info plist.
add LSApplicationQueriesSchemes Array
add whatsapp String.
If error is invalid url.
2) Check, whether the string you are passing is not having special characters. Specially whitespace.
string = [string stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
then use this string for url.
Both of these should solve. Cheers!

Use NSScanner or NSRange for url to find NSSet objects

Basically I'm trying to find NSSet objects contained in a url for my webview.
How would I use NSScanner or NSRange to do this?
Below is what I'm working with.
//External file links
NSURL* externalURL = [request URL];
NSString *externalFileExtension = [[request URL] pathExtension];
//External file extensions
NSLog(#"fileExtension is: %#", externalFileExtension);
NSSet *supportedFileExtensions = [NSSet setWithObjects:#"mpeg", #"mpg", #"m1s", #"mpa", #"mp2", #"m2a", #"mp2v", #"mv2", #"m2s", #"avi", #"mov", #"qt", #"asf", #"asx", #"wmv", #"wma", #"wmx", #"rm", #"ra", #"ram", #"rmvb", #"mp4", #"3gp", #"3gpp", #"ogm", #"mkv", #"flv", #"mv4", #"srt", #"swf", #"vob", #"aif", #"iff", #"m3u", #"m4a", #"mid", #"mp3", #"mpa", #"wav", #"aac", #"7z", #"cbr", #"deb", #"gz", #"pkg", #"rar", #"rpm", #"sitx", #"tar.gz", #"zip", #"zipx", #"ipsw", #"bin", #"cue", #"dmg", #"iso", #"mdf", #"toast", #"vcd", #"torrent", #"nes", #"rom", #"doc", #"docs", #"msg", #"odt", #"rtf", #"txt", #"wpd", #"wps", nil];
if ([supportedFileExtensions containsObject:externalFileExtension]) {
//my actions
}
Because of the type of links, some sites don't exactly use file extensions, some use the extension type in the link i.e. "zip=blahblah" or "blahblahzipblah'
I need to search the link clicked to find the supportedFileExtensions portion.
Thank you in advanced.
UPDATE:
Thanks to rmaddy for getting me in the right direction. For my original question, it did solve it. But I am having issues with the use on some other sites.
I have a webview in which I have a few links to different sites like Media Fire, Copy, Box, etc. Even a direct download link. The media fire link for example starts the download without even going to the site, almost like its just downloading the text. The direct download wont even fire my downloader at all.
Using the accepted answer, what would be the cleanest way to distinguish these?
The following should be what you want:
//External file links
NSURL* externalURL = [request URL];
NSString *urlString = [externalURL absoluteString];
NSSet *supportedFileExtensions = [NSSet setWithObjects:#"mpeg", #"mpg", #"m1s", #"mpa", #"mp2", #"m2a", #"mp2v", #"mv2", #"m2s", #"avi", #"mov", #"qt", #"asf", #"asx", #"wmv", #"wma", #"wmx", #"rm", #"ra", #"ram", #"rmvb", #"mp4", #"3gp", #"3gpp", #"ogm", #"mkv", #"flv", #"mv4", #"srt", #"swf", #"vob", #"aif", #"iff", #"m3u", #"m4a", #"mid", #"mp3", #"mpa", #"wav", #"aac", #"7z", #"cbr", #"deb", #"gz", #"pkg", #"rar", #"rpm", #"sitx", #"tar.gz", #"zip", #"zipx", #"ipsw", #"bin", #"cue", #"dmg", #"iso", #"mdf", #"toast", #"vcd", #"torrent", #"nes", #"rom", #"doc", #"docs", #"msg", #"odt", #"rtf", #"txt", #"wpd", #"wps", nil];
for (NSString *extension in supportedFileExtensions) {
if ([urlString rangeOfString:extension].location != NSNotFound) {
// Found extension somewhere in the URL - process it as needed
break; // stop looking for more
}
}
Perhaps something like this without using NSScanner or NSRange:
BOOL result = NO;
for (NSString *extension in supportedFileExtensions) {
if ([externalFileExtension isEqualToString:extension]) {
result = YES;
break;
}
}

iOS - Cannot deep link into official Facebook client ("The page you requested was not found")

I've followed other questions on this however, What seems to work for them doesn't seem to work for me. I tried putting in the hard value directly into the facebookURL variable, still I get the same result. It opens the facebook app, and gives the message "The page you requested was not found".
NSDictionary *profile = [PFuserProfile objectForKey:#"profile"];
NSString *facebookId = [profile objectForKey:#"facebookId"];
NSMutableString *fullText = [NSMutableString string];
[fullText appendString:#"fb://profile/"];
[fullText appendString:facebookId];
NSURL *facebookURL = [NSURL URLWithString:fullText];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
NSLog(fullText);
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
NSMutableString *fullText2 = [NSMutableString string];
[fullText2 appendString: #"http://facebook.com/"];
[fullText2 appendString:facebookId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fullText2]];
}
the second option, if the app isn't installed, works perfectly.

Skype Url not working in Objective C?skype://USER_NAME?call (New Skype Have Disabled the Feature)

I am using open URL for the Skype application to call the specific user from my iOS App.
but following code just opens Skype but does not call the specified user name.
can anyone please guide me on why it's not calling.
- (IBAction)callSkypeUser:(id)sender
{
NSLog(#"%s", __PRETTY_FUNCTION__);
NSString* urlString = [NSString stringWithFormat:#"skype://USER_NAME?call"];
NSLog(#"url = %#", urlString);
BOOL result = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(#"result = %d", result);
}
Your URL is not valid.
According to Skype reference your URL string should be like:
NSString* urlString = [NSString stringWithFormat:#"skype:USER_NAME?call"];

try to use rangeOfString to behave url for youtube video

I need the app recognize if it's a youtube video embed, then in-app webView
Here is the code I'm using now:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSString *urlString = request.URL.absoluteString;
NSString *youtube;
youtube = #"youtube";
if ([urlString rangeOfString:youtube options: NSCaseInsensitiveSearch].location != NSNotFound){
return YES;
}
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
That works in most cases because most youtube links are directly transferred as embedded video already on the webpage. However, I check if i choose a profile page or others from youtube, this will still open in-app, becuz my app doesn't have back button (buttons in html page). So any link that's not to a video will cause can't return.
I tried use #"youtube.com/watch" #"/watch?" #"watch?" as rangeOfString, but only youtube works.
For example:
This a youtube video url: data-url="http://youtube.com/watch?feature=player_detailpage&v=Ke1Y3P9D0Bc" (in-app view good)
dara-url="youtube.com" (fail, still in-app view)
I wonder either i stored string by wrong format, symbols not support in rangeOfString?
Or there can be another way like urlString rangeOfString:youtube && #"watch"
Thank you for this, really appreciate.
NSURL *myURL = [NSURL URLWithString:#"http://www.youtube.com/watch?feature=player_detailpage&v=Ke1Y3P9D0Bc"];
NSString *host = myURL.host;
NSString *path = myURL.path;
NSLog(#"%#", host); // Output: www.youtube.com
NSLog(#"%#", path); // Output: /watch
NSLog(#"%#", myURL.query); // Output: feature=player_detailpage&v=Ke1Y3P9D0Bc
if (NSMaxRange([host rangeOfString:#"youtube.com" options:(NSCaseInsensitiveSearch|NSBackwardsSearch)]) == host.length &&
[path.lowercaseString isEqualToString:#"/watch"]) {
NSLog(#"This is a youtube video.");
}
You can certainly use,
if ([urlString rangeOfString:youtube options: NSCaseInsensitiveSearch].location != NSNotFound && [urlString rangeOfString:#"watch" options: NSCaseInsensitiveSearch].location != NSNotFound)
Whether that will get you what you want, I don't know, but it should work as a valid if statement.

Resources