Map app not working - ios

Have a look at the below code it's working properly
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];
but it opens map in safari browser.
after that i've tried below code
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];
it open map app as i desired but not giving me the directional result with route or the same result that above google map gives how can i achieve the result as first code in map app?
please help!!

Apple's map does not have the same API as google maps, thus you URL will not work. With iOS 6 apple introduced the MKMapItem which allows developers to interact with the maps.app.
If you want to keep using the the maps via http then you should change you url:
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];
As stated in the Apple URL Scheme Reference you should not add the /maps/ path.
URLs that contain no path parameters or that contain specific map
paths are opened in Safari and displayed there. For example, URLs
based on the paths http://maps.apple.com/, http://maps.apple.com/maps,
http://maps.apple.com/local, and http://maps.apple.com/m are all
opened in Safari. To open a URL in the Maps app, the path must be of
the form http://maps.apple.com/?q.
The rules for creating a valid map link are as follows:
The domain must be maps.apple.com.
The path cannot be /maps/*.
A parameter cannot be q=* if the value is a URL (so KML is not picked up).
The parameters cannot include view=text or dirflg=r

Related

opening a url with hashes

this is my url which I want to open from the IOS App :
NSString *urlString = #"https://cms.topmerits.com/CRM/feedback#/1715171559ae979371687#/10306";
when I encode it, the hashes are transferred to %
NSString *feedbackUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
therefore the new url is :
https://cms.topmerits.com/CRM/feedback%23/1715171559ae979371687%23/10306
which does not open, it leads to a crash on the server side. any idea how to solve this issue

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!

how to send file from from one app to another app using url scheme?

Summary (iOS 8, Xcode 6.4)
First question:- Can i share my app's Documents Directory's data with my other app?
If Yes, I've seen many questions related to this;
Move data/images between two iOS apps using custom URL handler,
http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629
But I found that these example only send text or URLs. Then I tried myself as below:
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://"];
NSURL* url = [NSURL URLWithString:path];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
The above code works well to open my other app. But when I try like below, I can't open my other app.
NSArray* mainPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourcePath = [mainPath objectAtIndex:0];
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://%#",sourcePath];
NSURL* url = [NSURL fileURLWithPath:path isDirectory:YES];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
So, please help me, what am I missing?
EDIT:-
i forgot to mention that,iOS7 support is important in my App.so, i think extension might not work.
Use NSUserDefaults with app group to share the data between apps
NSUserDefaults *defaults=[[NSUserDefaults
alloc]initWithSuiteName:#"app group name"];
[defaults setObject:filedata forKey:#"keyfordata"];
[defaults synchronize];
in the app delegate of consuming app fetch the data from NSUserDefaults
another way is to use share extension-
http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/
You can refer MGInstagram files as Instagram mobile app works same. You can pass image from your application to Instagram application.
You can download it from here: https://github.com/mglagola/MGInstagram
Hope this helps.

Pass an Url to image view through AFNetworkingLibrary

The project was created with xcode 4.3.
I have used AFNetworking Library (non-ARC) in this app.
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, when I print a NSLog value, am getting the URL but the imageview is not displayed.
How can I solve this?
Your code is fine, problem is with URL.
Your URL, don't have prefix, http://, I added it and the code is same as in quesiton.
NSString *urlstring = #"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, you've three options to fix this,
1) If URLs are not coming from server (or some where else) you can fix it within the app, see how,
NSString *badUrlString = #"mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSString *goodUrlString = [NSString stringWithFormat:#"http://%#",badUrlString];
2) Or if its coming from server (or some where else) you can ask them to fix this from their side.
3) If its under 2nd option then, ask them if this will always happen (static) then you can also modify this from your side if server side developers not able to fix.
see this for more help, Check string containing URL for "http://"
Yes,
I also tried your url, it is working fine.
I loaded it as:
NSURL *correctURL = [NSURL URLWithString:#"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg"];
_imgFromUrl.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:correctURL]];
And the result,

Calling a URL from a Label

I've parsed a YouTube link from a remote XML file and placed the string into a Label that the user sees. Now I want to open it using that label's text ("link0" is the label name). The log shows the label properly populated with the URL....
NSString *stringURL = [NSString stringWithFormat: #"%#", link0.text];
NSLog(#"%#\n",stringURL);
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
But it's not working. If I manually insert the link into the above code, it works. How do I convert text from a label "link0" into a useable URL string? Thank you.

Resources