Location background service not working in Swift2 - swift2

I have some odd behaviour in my app.
In my app delegate file I ask the user for permission to use their location while they use the app. This works fine and I can get their current location. After I get their initial location I stop updating location. Great. There is a button users can tap to start updating locations.
If the app is in the foreground I can see that locations are being added to my dictionary every second (I will change this to distanceFilter 10 later). If the user puts the app in to the background location services stop and I don't see the blue bar at the top of the screen.
I have:
Background modes for location updates enabled
NSLocationWhenInUseUsageDescription set (I am able to successfully ask the user for permission)
Started the location updates with startUpdatingLocation()
Tried setting the app to track location always (same result)
Deleted the app from my phone and reinstalled
In the previous version of my app (before Swift 2) this was working perfectly. I could see location being tracked even when the app was in the background.
I am testing on my iPhone not the simulator.

If anyone else has the same issue, I had updated my iPhone to iOS9 so it was required for me to add
locationManager.allowsBackgroundLocationUpdate = true
to my location manager.

The following worked for me, please note allowsBackgroundLocationUpdates is plural.
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.allowsBackgroundLocationUpdates = true

Related

IOS 8 Location Services Not Working

Summary:
Previously running apps failed to run geode code and reverse geode code. The reverse geode code fails because the geode code fails to provide a location. I then swathed to Apple's own LocateMe example code and also enabled the Location Services under Privacy. I also enabled the "Allow Location Access" under Location services to Always, but this setting changes back to nothing by itself after running the Apple's LocateMe or my own app.
Steps to Reproduce:
It seems location services SDK to get location is broken. The software that was previously working on iPhone 5 stopped working after upgrade to IOS 8.
Step 1. Load example LocateMe Apple's example Core Location example project;
Step 2. Under system settings enable Location Services, and also change the app's "allow Location Services" to always.
The Get-Location fails and "always" setting is removed.
Expected Results:
Getting location and location updates.
Actual Results:
See above.
Version:
IOS 8.0.0 and 8.0.2
Notes:
Configuration:
iPhone 5 and iPhone 6 Plus
Adding this this not help either:
[self.locationManager requestAlwaysAuthorization];
Use
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) \
([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8")) {
CLLocationManager *manager = [[LocationManager sharedInstance] clLocationManager];
[manager requestWhenInUseAuthorization];
[manager startUpdatingLocation]; // or what ever location function you need.
} else {
// The usual way for iOS <= 7
// (Do what you did before)
}
In addition to the above, you will have to add a string value for the key NSLocationWhenInUseUsageDescription in your info.plist file. The value is the string that is presented in the Altert when iOS asks the user whether to grant access to locations for your app or not.
For backward compatibility you may want to add the key NSLocationUsageDescription too.

Location services not updating in background

For iOS 8 I have added the following key to my plist:
NSLocationAlwaysUsageDescription
I also added:
// Check for iOS 8
if ([_locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[_locationManager requestAlwaysAuthorization];
}
I deleted the app from my phone. Upon launch I get prompted if its ok to run location services in background as expected. I click yes. While the app is running I get locations and the location active icon is in the status bar.
However if I leave the app the location active icon soon disappears from the status bar and I no longer get locations.
Do I need to re setup the location manager when the app enters the background? Does the location manager property/variable need to be defined in the AppDelegate such that it never goes away?
You also have to set location updates in the background modes of your capabilities.

IOS8 LocationServices, permission reverts to neither allowed or disallowed. doesn't update location

I am running IOS8 on this device.
I'm using location services for an ios app. It has worked well for a long time, however recent I am no longer receiving location updates.
One thing I checked is in Settings->Privacy->Location Services, whether it was enabled for the app. Oddly, while all other apps were set to Always, or Never, my app was the only one with a blank value. Neither was set. After I choose Always, and run the app, it doesn't help. When coming back to settings it is once again blank.
Interestingly, the same code works fine on my other IOS7 device, with location updates okay.
A few additional settings are needed for IOS8 location services to work out of the box. It is described here well. This solved it.
Location Services not working in iOS 8

Change OSX Notification Center icon at runtime

Is there (now) a officially supported way to change the OSX Notification Center's Icon for NSUserNotifications while my App is running?
I searched the web, but the answers weren't really "recent", so I just wanted to double check.
I'd like to show the currently playing spotify track's Artwork next to it's title / name
What I tried until now is really ugly:
temporarily replacing the CFBundleIconFile of my app with a IconFamily generated .icns file (I know i shouldn't modify anthing inside the bundle, but I'm not aiming to get the app to the App Store)
restart Notification Center to "forget" it's eventually cached icons
NSRunningApplication* notificationCenter = [NSRunningApplication runningApplicationsWithBundleIdentifier:#"com.apple.notificationcenterui"];
[notificationCenter terminate];
(i know I REALLY SHOULDN'T do this)
If you are NOT going to submit your app to App Store, there's a private API in 10.9 that does what iTunes did:
NSUserNotification *notification = [NSUserNotification new];
[notification setValue:anImage forKey:#"_identityImage"];

Location indicator persists on status bar after stopUpdatingLocation is called, but only for old Bundle Identifier

Does any one know why the location indicator stay on for certain bundle identifer vs. the others?
I am using an Apple sample LocateMe app, installed on my iOS device running version 5.0.1. When I'm using an old bundle identifier, the location indicator stays on the status bar, after the CLLocationManager stopUpdatingLocation is being call.
But, when I'm using the same exact app, with the only difference being a new bundle id, the app works as expected and the location indicator disappear once the stopUpdatingLocation is being called.
Did anyone experience this problem or can explain it?
I finally figured that if I reset the Location Warnings from the Settings, the bug disappear.
From your iOS Settings select General | Reset | Reset Location Warnings. This will reset the warning to all the apps. This mean that the next time you start an app that requires location, the iOS will prompt you with the location permission dialog.
Select 'Reset Warnings' from the action sheet.
When running the app again, the iOS will prompts you with the location permission dialog (if it doesn't - repeat the process above to reset the location warnings). After selecting yes, the app behaves as expected, and the location indicator disappears after few seconds.
Did you try to also stopMonitoringSignificantLocationChanges ? It worked for me.

Resources