How to get directions in iOS 6 on new Apple Maps? - google-maps

I've an app builded for iOS < 6, and before it all the features work perfectly. Now I've used a switch that recognizes the iOS installed on a device and then my app opens the correct maps to get directions from the local position to another (some pins on the map). The problem is that before iOS 6, the app opens the native maps and show the route to the user. Now, If the device uses iOS 6, the app opens the Apple Maps but shows a pop-up with something like "Impossible to get direction between this 2 positions". Why? Can someone helps me to solve this problem?
Here how I pass the coordinate to maps from a disclosure button:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
if (SYSTEM_VERSION_LESS_THAN(#"6.0")) {
NSString* addr = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
else {
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}

Whilst you can use the URL method for maps (http://maps.apple.com/...), I've found it not to be great when presenting specific locations. Your best bet would be to use MapKit objects on iOS 6 and above.
Example:
CLLocationCoordinate2D location;
location.latitude = ...;
location.longtitude = ...;
MKPlacemark* placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];
MKMapItem* item = [[MKMapItem alloc] initWithPlacemark:placemark];
//... Any Item customizations
NSDictionary* mapLaunchOptions = ...;
[item openInMapsWithLaunchOptions:mapLaunchOptions];
This will open Apple Maps directly, with the item you have provided.
In order to deal with directions, use the MKLaunchOptionsDirectionsModeKey launch option, and provide the start and end map items via:
[MKMapItem openMapsWithItems:mapItems launchOptions:launchOptions];

Just to clarify the other answer, you have two options when giving directions: driving or walking. Here are the ways to do each one:
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
//This is for driving
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}];
//This is for walking
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}];
More info from Apple's docs over here.

Related

Display a preview of the website

I need to display a preview of the website with given url in the single image(e.g. like Facebook do in Messenger when you sending a url to someone). Is there any way to achieve that without actually loading the html file and reading it's metadata?
Try this,
NSString *urlStr = #"http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a";
NSURL *url=[NSURL URLWithString: urlStr];
NSData *data=[NSData dataWithContentsOfURL:url];
UIImage *image=[[UIImage alloc] initWithData:data];
UIImageView *imagview = [[UIImageView alloc]initWithImage:image];
imagview.frame = CGRectMake(250, 500, 100, 100);
[self.view addSubview:imagview];
This will give just thumb or image.
You can use URLEmbeddedView Library for more functionality. I think this is the library what you want.

Reduce html file loading time in phonegap application ios?

iam working on a simple phonegap application in that it takes around 3 minute to load the file(for showing home page ) till that time it showing the splash image(launch screen) is there any way to make it fast???
Total "WWW" folder file size is 5.3MB
my app delegate application didFinishLaunchingWithOptions() show below
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
#endif
self.window.autoresizesSubviews = YES;
#if __has_feature(objc_arc)
self.viewController = [[MainViewController alloc] init];
#else
self.viewController = [[[MainViewController alloc] init] autorelease];
#endif
self.viewController.useSplashScreen = YES;
// Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = #"index.html";
// NOTE: To customize the view's frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I've known other people with similar issues (but not 3 minute delays!), I'm not sure there is much you can do, I think we need to wait for the PhoneGap people to develop a system that makes it more efficient in loading.

FacebookLikeView crashing all the time iOS

I've been using the FacebookLikeView classes in a lot of apps to enable Facebook profile liking within apps. Recently the code has started crashing in every app I've put it in. The Facebook app is setup correctly and everything. This is the line it is giving an EXC_BAD_ACCESS on:
else if ([fbEvent isEqualToString:#"xfbml.render"] && [_delegate respondsToSelector:#selector(facebookLikeViewDidRender:)])
[_delegate facebookLikeViewDidRender:self];
And it's being implemented like so:
_facebook = [[Facebook alloc] initWithAppId:fbAppID andDelegate:self];
self.facebookLikeView = [[FacebookLikeView alloc]init];
[self.facebookLikeView setFrame:CGRectMake(117, 140, 82, 19)];
self.facebookLikeView.delegate = self;
self.facebookLikeView.href = [NSURL URLWithString:user];
self.facebookLikeView.layout = #"button_count";
self.facebookLikeView.showFaces = NO;
[self.facebookLikeView load];
You should set your facebookLikeView to nil in your dealloc method or viewdidunload method

How to load a second view controller with a swipe gesture?

I have a Tabbed Based application and I want to use swipe gestures to navigate through the view controllers.
I tried:
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender {
UISecondViewController *second =[[UISecondViewController alloc] initWithNibName:#"UISecondViewController" bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second animated:YES];
}
paired with this:
- (void)viewDidLoad; {
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeftDetected:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
}
But it crashes on the swipe. Any help? Thanks!
Your code works well on my Xcode.
Only changed:
UISecondViewController *second =[[UISecondViewController alloc] initWithNibName:#"UISecondViewController" bundle:nil];
to:
SecondViewController *second =[[SecondViewController alloc] init];
because I don't have the UISecondViewController class.
Just verify there is UISecondViewController.xib in your project, otherwise it will crash.
But I'm not sure here is your problem.

Root View Controller?

I'm working with ShareKit, an open-source sharing foundation for iOS apps. There is a known bug that prevents the Kit from detecting what your root view controller is. The fix for that bug is adding [SHK setRootViewController:myViewController]; in the app delegate.
If the fix is in the UIApplication didFinishLaunching method, wouldn't the view controller just be self? What am I missing? I've also tried self.viewController, self.window.rootViewController and self.window to no avail.
EDIT: Here's the entire didFinishLoading:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[SHK setRootViewController:self.viewController];
return YES;
}
If it would only be "self" in the didFinishLaunching it would refer to the UIApplication, don't you agree? Are you initing correctly the viewController? Post some more code. :)
Comment to your Edit:
If you have your Window set normally in your XIB you don't need this:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Also, if you do this (presuming your viewController is retained as property):
self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];
You will have a leak. Just do this:
viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];