I'm using route-me (Alpstein fork) to show a map with user's location. It was working until I updated both Xcode and route-me recently. Now if I set :
mapView.showsUserLocation = YES;
mapView.userTrackingMode = RMUserTrackingModeFollowWithHeading;
Nothing happens. I downloaded the Mapbox-me project (https://github.com/mapbox/mapbox-me) to test if it is working with Mapbox, and it's not. I'm using the simulator for testing. The user location in iOS's Maps app is working, so the simulator seems to be able to send a position.
Is anyone facing the problem ?
Well, I was not looking in the good direction, the problem was absolutely not related to MapBox / route-me but to iOS 8 ...
To receive any location update we now need to add one of the following entries in the .plist :
NSLocationAlwaysUsageDescription (if your app needs location even in background)
NSLocationWhenInUseUsageDescription (if your app only need location when in foreground)
And we need to gently ask the user's permission by doing one of these calls (before asking MapView to display the user's position) :
if([_locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) [_locationManager requestAlwaysAuthorization];
if([_locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) [_locationManager requestWhenInUseAuthorization];
If you don't, you will get no error, no warning - and no location update... I definitely love Android development !
Related
Our app would like to access accelerometer data in background. A possible way to achieve is to use Core Motion for accelerometer readings -
with
CLLocationManager* locationManager;
CMMotionManager* motionManager;
...
[motionManager startAccelerometerUpdatesToQueue: ... withHandler: ...]
which works fine on the foreground, but the only way I've found to receive the updates in background is to set the app to allow using Location in background, and call
[locationManager startUpdatingLocation]
in -applicationWillResignActive:
The problem is, when I call startUpdatingLocation that a window pops up with text Turn On Location Services to Allow "app" to Determine Your Location.
But of course, I receive accelerometer readings regardless of whether Location Services are enabled, but the popup is annoying and will probably confuse users.
Is getting accelerometer data in the background somewhat tied to attempting to receive location updates?
You can use startAccelerometerUpdatesToQueue in background, the only thing you need to meet — use any background mode to make you app running in the background (location updates (your case), playback, VoIP or BT4 central).
I'm trying to implement a gamecenter aware app targeted to iOS 6. To give some info on the environment I'm working on mac os 10.7.5 with XCode version is 4.5.2 and xcode is running iphone and ipad simulator version 6.0. The problem is I cannot connect to gamecenter in sandbox mode neither through ipad or iphone simulator, but the same code works as desired while testing in my iphone.
I followed the gamecenter programming guide in apple's developer library and I got this atm it is called from applicationDidFInishLaunching in appdelegate:
- (void)authenticateLocalUser:(UIViewController *)currentViewController
{
if (!gameCenterAvailable) return;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil)
{
[currentViewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated)
{
NSLog(#"Player authenticated");
}
else
{
NSLog(#"Player not authenticated");
}
NSLog(#"Error: %#",error);
};
}
It outputs:
Error: Error Domain=GKErrorDomain Code=2 "The requested operation has been cancelled."
UserInfo=0x8690510 {NSLocalizedDescription=The requested operation has been cancelled.}
GKSConnSettings: set server: {
"gk-cdx" = "17.173.254.218:4398";
"gk-commnat-cohort" = "17.173.254.220:16386";
"gk-commnat-main0" = "17.173.254.219:16384";
"gk-commnat-main1" = "17.173.254.219:16385";
}
I already tried hosts file fix though my OS is not 10.8.2 but it didn't help. https://devforums.apple.com/thread/168811?tstart=0
Any idea what can be the possible cause?
Edit: Well, it turns out the output part starting with GKSConnSettings does not indicate any problems, that's the regular output while connecting to game center as I understood from what I read over internet. I printed the actual error message (GKErrorDomain = 2 ...) inside the authentication block.
I got the inspiration from : https://stackoverflow.com/a/8115807/837244, and decided to log in to game center account with a different piece of code. So in viewdidload I normally called:
[[GCHelper sharedInstance] authenticateLocalUser:self];
Now I commented that out, accessed game center through below URL scheme, logged in to my account and after that logged out.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];
And lastly reverted back by commenting out URL code and using the original code. Now it works fine, I guess the problem was that a game center account was already hooked up in simulator and it denied every login request bc of that. Hope apple goes clearer with error messages, it took a month to fix such a simple issue, may this help to others.
I know this question references specific Xcode and iOS simulation versions, but if your simulator is already logged in one account, and you don't mind losing whatever data you've got on the simulator (chances are small, but you never know), you can simply reset the settings and data on it.
Go to:
Simulator -> Reset Content and Settings...
...and confirm the action when prompted.
This is certainly true for Xcode7.x running an iOS 9.x simulator, someone else might be able to verify whether it's true for earlier versions (especially as I've unearthed quite an old question and answer).
Animal451
Necrothreadomancy: +1
I am using the route-me files found at https://github.com/route-me/route-me to build a offline map application for iPhones.
I have the map working offline and also successfully implemented "current location" button that will show the users location on the map with a marker.
Now, I want to be able to let the users be able to drop "pins" on the map so that users can get the coordinates of the "pins" that user just dropped on the map. (separate from the current location)
I have tried to look for tutorials and other helpful documents on Google but all the information that I've found are using the MapKit lib and framework
If any of you are expert on route-me and using RMMapView to make offline maps, it would be awesome if you guys can help me out.
Thanks
For droping pins on RMMapview , this is required snippet of code used in - (void)viewDidLoad after creating RMMapview
RMMarkerManager *markerManager = [[[RMMarkerManager alloc] initWithContents: mapView]autorelease];
RMMarker *marker = [[RMMarker alloc]initWithUIImage:[UIImage imageNamed:#"marker-blue.png"] anchorPoint:CGPointMake(0.5, 1.0)];
[marker setTextForegroundColor:[UIColor blueColor]];
[markerManager addMarker:marker AtLatLong:(CLLocationCoordinate2D){40.988,23.098}];
[marker release];
I need to get the user's location even if the phone goes to sleep/screen lock mode. I've tried enabling location services in background mode by adding key to the info.plist file, but this method requires iOS >= 4.0. Is there any alternate method to get the location manager working in screen lock mode
Yes. Have a look at this:
http://github.com/marcop/iPhoneInsomnia
It keeps the iDevice awake by registering your app as an audioplayer and playing a silent sample every 5 seconds. AFIK, this is the only way to do it in iOS < 4.0.
It seems like a hack, so I don't know what Apple thinks of it, still there are a lot of apps in the AppStore that apparently does this.
I have what i thought was a relatively simple question but i cannot find an answer to it yet. I have an iPhone app that uses GPS on one of its screens. I want to disable this screen using code when the app loads,so disable it when a iPod touch is being used. This is so it can still be useful on a iPod touch as there is a lot of functionality that a iPod touch user can use.
Thanks.
You can get there with #Aaron's answer, but that's not the way to do it. Use [CLLocationManager locationServicesEnabled]; to tell if you can determine the users's location. This is a lot more robust than making decisions based on the device model.
to get the device info..
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html
NSString *deviceType = [UIDevice currentDevice].model;
I think if you are just checking for GPS then you will need to access the CLLocationManager to see if it is on or off