My app needs to track background location for a period of several hours while the user is using it, and we want to allow the user to switch apps or lock their phone while this is happening. We don't need to track location permanently and because of this, we don't want to request the "Always allow" permission.
The app requests "While in use" permission and it has the "Location updates" background mode enabled. The CLLocationManager has 'allowsBackgroundLocationUpdates' set to true, 'pausesLocationUpdatesAutomatically' false, kCLLocationAccuracyBest, kCLDistanceFilterNone, and .fitness for the activity type (we expect the user to be walking).
The app also initializes a CLBackgroundActivitySession while it is tracking location and invalidates it when done.
When I test this combination on my iPhone, it works fine. I get location tracking in the background for as long as I need it, regardless of what else I do with the phone.
However, my customer says it doesn't work for him. He is using a Wifi-only iPad with an external GPS receiver called "BadElf GPS Pro". He says that the external GPS receiver works fine with other apps on his iPad. With my app, he gets background location tracking only for a short time, and then it stops.
The app does monitor the "locationManagerDidPauseLocationUpdates" callback and posts a local notification if it gets called, but it doesn't get called. I've also confirmed with him that he is not force-quitting the app and the app is not otherwise being terminated by iOS.
Is there something I'm missing?
Post
Replies
Boosts
Views
Activity
I manage apps and servers on behalf of several customers. Recently they all started getting a message from Apple that says, "The Certification Authority for APNs is changing".
I don't understand how or if this affects me. My servers are all hosted on Amazon EC2 instances. I have never had to install any specific certificate for APNs to work.
Is this new CA something that I can expect my servers to receive automatically as part of their system updates? If not, how do I install it?
class A: Codable {
var x: String?
}
class B: A {
var y: String?
}
When I try to decode class B, the property "y" remains nil even though there is a value for it in the JSON data. If I change it to B: Codable then it works.
When I try to search for a solution, all I can find is people overriding init methods and doing decoding manually in some way. I am having a hard time believeing that this is the right answer.
Surely, coding works across class hierarchies?
I have a tableview and I want to use a custom section header.
Instead of writing out all the code to create the section header, I added the view to my XIB file and connected it to an outlet in my view controller. I hid the view behind another view so it isn't visible and doesn't take up any room in the layout of the screen.
In my view controller, I removed the view from the layout (removeFromSuperview) and then I returned it from my viewForHeaderInSection function. I also implemented heightForHeaderInSection to make sure I get the right height.
When I run my app, what shows up is a blank space in the table where I'm expecting the header view to be. The space is the right height, but there is nothing in it. I do not understand why.
The crash logs for my app show an occasional crash that happens during the launch of the app. The highlighed line is "CoreBluetooth -[CBUUID initiWithData:]. The stack trace ends with "static AppDelegate.$main()".
My app does use Core Bluetooth, but there are no Bluetooth related functions in the App Delegate. Also, my app does not use [CBUUID initWithData:] explicitly anywhere.
With a stack trace that contains no reference to any of my code, it is extremely difficult to figure out what is going on. I cannot reproduce the crash on any of my own devices. One of my affected users says the app crashes on startup on his phone consistently, even if he deletes and reinstalls it.
My app downloads files from AWS S3. What we'd like to do is replicate our files across several of Amazon's data centers (regions) to put the content closer to our users, who are worldwide.
What I need is a way to determine in a very ***** way which data center would be best to use. For example North America, Europe, Asia, etc. I don't want to use location services since I don't really need the exact location. Is there a simpler way to do this?
I suppose I could use the localization settings, but I don't think that's really guaranteed to represent their actual location.
Thanks,
Frank
I have some Swift classes in my project that extend an Objective-C base class, which in turn extends NSObject. I did this years ago when Swift was new in order to take advantage of some Objective-C code that was difficult to rewrite in Swift. It's not a common situation but it has been working fine for a long time.
One of these classes is used as the key to a Dictionary and thus needs to be Hashable. The way I did this was to implement an == function and override the 'hash' property. It is a very simple case where the identity of the object is based on a single integer:
static func == (lhs: FishModel, rhs: FishModel) -> Bool {
return lhs.fishId == rhs.fishId
}
override var hash: Int {
return fishId
}
I believe that I initially tried to add "Hashable" to the class definition but was told it was redundant. I'm not sure why that is, but it worked fine without it.
Today I took the latest Xcode update to 15.2, and now my project won't compile anymore. The compiler error says that my class "does not conform to protocol Hashable". Adding Hashable to the class definition did not fix it. There are also some unusual errors about missing files, such as abi.json, swiftdoc, swiftmodule, and swiftsourceinfo.
Was this caused by the Xcode update? How do I fix it?
I wrote an app for my own personal use. It is loaded onto my iPhone as a debug build and I also have a build on my Mac. These builds expire every few months and force me to go back into Xcode and rebuild them. Is there a better solution?
I am not an enterprise and don't have a business account, I'm just an individual developer.
I can't get Xcode to permanently remember my Git credentials. It remembers them for as long as Xcode is open, but when I close it and re-open it later, it prompts me for the credentials again. I don't see any kind of an option to save them.
I use the 'git' command-line program on my computer and I've stored my credentials there, but Xcode doesn't seem to be able to access them that way.
How can I get Xcode to remember my credentials?
I added an asset catalog to an old iOS project that I'm in the process of updating. The app was originally created before asset catalogs existed.
I added an image and an icon set to my catalog. The icon works, and the image shows up when I run the app, but Interface Builder doesn't recognize the image by name when I type it into the Image field on an imageview.
I'm guessing that there is something somewhere which causes interface builder to read an asset catalog, which is probably not set on my old project, but I can't figure out what it is.
Thanks,
Frank
I'm using JSONDecoder().decode(T.Type, from: data) to decode a JSON response from a server. It works in some cases but eventually my program crashes with the error "Stack buffer overflow".
The size of the JSON data I'm trying to decide is about 16k, which is large, but not unusually so.
The decode is happening in a non-main thread, but I tried pushing it into the main thread with the same results.
Most of these crashes occur in the simulator rather than on a real device, but I'd like to figure out the problem anyway.
I thought I'd try dispatching the work into a queue with a larger stack size, but I couldn't figure out how to make one. Is it possible?
Thanks,
Frank
Suppose I have two instances of CBCentralManager:
let manager1 = CBCentralManager(delegate: delegate1, queue: nil)
let manager2 = CBCentralManager(delegate: delegate2, queue: nil)
If I scan for peripherals using manager1, can I take the CBPeripheral that it gives me and connect to it with manager2?
Frank
Hi,
I'm trying to learn how to use asynchronous functions in Swift. I've used async functions in other languages such as C#, so I understand the general concept.
I want to call getPendingNotificationRequests on UNUserNotificationCenter asynchronously, so I wrote this:
let notificationCenter = UNUserNotificationCenter.current()
let requests = await notificationCenter.getPendingNotificationRequests()
This seems to match the examples I see in documentation, but it doesn't work. All I get is a compiler error that says "Missing argument for parameter 'completionHandler'". What am I doing wrong?
How do I change the timezone on the simulator? I need to test how my app works in other timezones.
Did something just change in Swift with regard to initializer inheritance?
Since installing Xcode 14.3, I have some code that is flagged with errors when I try to initialize a class using an initializer inherited from its superclass. This has always worked in the past.