Issue #101

I have Unit tests and UI tests pass on my simulator and device, locally. But when I make the build on Buddybuild, it fails with the reason Activity cannot be used after its scope has completed. People seem to have the same issue too.

Taking a look at the log in Buddybuild

 t =     8.89s     Staging: UIStatusBarWindow
t =     8.95s     Staging: (CoreFoundation) Sending Updated Preferences to System CFPrefsD
t =     8.95s     Staging: Setup BuddybuildSDK
t =     8.98s     Staging: [BuddyBuildSDK] In app store - Instant Replay Disabled
t =     8.98s     Staging: Setting up the remote notifications for UI Tests video recording
t =     9.07s     CL: CLLocationManager
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"CLLocationManager", "event":activity, "_cmd":initWithEffectiveBundleIdentifier:bundle:, "self":"0x600000205140", "identifier":(null), "bundle":(null)}
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Core] {"msg":"state transition", "event":state_transition, "state":LocationManager, "id":"0x600000205140", "property":init, "new":'00 00 00 00 00 00 F0 BF 00 00 00 00 00 00 F0 BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0 3F 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00'}
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Core] {"msg":"state transition", "event":state_transition, "state":LocationManager, "id":"0x600000205140", "property":lifecycle, "old":"0x0", "new":"0x6040000ddd50"}
t =     9.07s     CL: _CLClientCreateWithBundleIdentifierAndPath
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"_CLClientCreateWithBundleIdentifierAndPath", "event":activity, "effectiveBundleIdentifier":(null), "effectiveBundlePath":(null)}
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"client allocated", "client":"0x7f84c64e0990"}
t =     9.07s     CL: _CLClientCreateConnection
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"_CLClientCreateConnection", "event":activity, "client":"0x7f84c64e0990"}
t =     9.07s     CL: Sending cached messages to daemon
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"Sending cached messages to daemon", "event":activity}
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] #Warning No cached registration message
t =     9.07s     Staging: (CoreLocation) [com.apple.locationd.Core.Core] {"msg":"state transition", "event":state_transition, "state":LocationManager, "id":"0x600000205140", "property":pausesLocationUpdatesAutomatically, "old":0, "new":1}
t =     9.10s     CL: CLLocationManager
t =     9.11s     Staging: (CoreLocation) [com.apple.locationd.Core.Client] {"msg":"CLLocationManager", "event":activity, "_cmd":setDelegate:, "self":"0x600000205140", "delegate":"0x60400028bef0"}
t =     9.12s     error: unexpectedly found nil while unwrapping an Optional value
t =     9.12s             Unable to monitor event loop
t =    10.13s Tap "Onboarding.Continue" Button
t =    10.13s     Wait for no.hyper.MyApp-Staging to idle
t =    10.16s     Find the "Onboarding.Continue" Button
t =    11.28s         Assertion Failure: <unknown>:0: no.hyper.MyApp-Staging crashed in MyApp_Staging.AppDelegate.(makeDependencyContainer in _5D394B3D7D393F9C3C550E61780517BB)() -> MyApp_Staging.DependencyContainer
t =    11.33s Wait for com.apple.springboard to idle

Did you see unexpectedly found nil while unwrapping an Optional value? It crashed in CLLocationManager. It is because when location changes, CLLocationManager needs to report it via didUpdateLocations function, but we haven’t implemented it. Strangely that it didn’t happen when testing locally.

The proposed fix is to implement a dummy method with no operation

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  // No op
}

But it is not the solution. It appears that BuddyBuild is doing some hacks with how push notification and UIWindow, hence causing the issue.