Thank you - I think you nailed it, I think it's the background session completion handler that's getting dropped; it looks like my handleEventsForBackgroundURLSession function is not getting called, so I'm not getting the completion handler.
We're using Cordova, so I'm swizzling in this function because we don't have access to the app delegate class. I'm doing this for push notification callbacks, and those are working fine, but I don't see why this function is not getting called.
In Cordova's pluginInitialize, I'm calling:
static let bgSendingIsSetup:Bool = {
NSLog("CordovaInterface bgSendingIsSetup")
let app: UIApplication = UIApplication.shared
let appDelegate = app.delegate as! CDVAppDelegate
let clazz = CDVAppDelegate.self
appDelegate.swizzle(clazz, #selector(appDelegate.application(_:handleEventsForBackgroundURLSession:completionHandler:)),
#selector(appDelegate.swizzled_application(_:handleEventsForBackgroundURLSession:completionHandler:)))
return true
}()
That swizzle function is:
extension CDVAppDelegate {
func swizzle(_ clazz:AnyClass, _ originalSelector:Selector, _ swizzledSelector:Selector) -> () {
let original = class_getInstanceMethod(clazz, originalSelector)
let swizzled = class_getInstanceMethod(clazz, swizzledSelector)!
if let origMethod = original {
method_exchangeImplementations(origMethod, swizzled)
Log.log("swizz swapped \(originalSelector) w/ \(swizzledSelector)", true)
} else {
class_addMethod(clazz, originalSelector, method_getImplementation(swizzled), method_getTypeEncoding(swizzled))
Log.log("swizz added \(originalSelector)", true)
}
}
And this is the signature for my replacement function, which looks right to me:
@objc dynamic func swizzled_application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
Log.log("hEFBUS \(identifier)", true)
...
... but the hEFBUS line never actually gets logged.
I'm swizzling the push notification functions (didRegisterForRemoteNotificationsWithDeviceToken, didFailToRegisterForRemoteNotificationsWithError, and didReceiveRemoteNotification:fetchCompletionHandler) at the same point and using the same swizzle function, and those are working... what am I missing?