Different behaviour when starting app from Xcode than from iPhone

I am developing an app to control DJI drones by using DJIs Mobile and UX SDK. I am aware, that the problem I am facing might be related to their code, but I am hoping for some pointers on where to look at or things I can try to troubleshoot the issue.

I have explained the issue with code examples and screenshots on Stackoverflow: https://stackoverflow.com/q/67320963/1065468

The remote of the drone is plugged into my iPhone and I start the app through Xcode on my phone wirelessly over the network.

While the app works as it should when started from Xcode, it does not work when I just press the app icon on the iPhone.

Checking my log output of the app on the phone in the console of my Mac, I can see, that the underlying connection to the drone is working and the app should update.

Could it be a difference in configuration when the app is started from Xcode or directly from the phone?

Looking forward to any pointers from you to help me troubleshoot this problem.
Answered by twissmueller in 673682022
Finally, it works!

I had to re-introduce the AppDelegate with @UIApplicationDelegateAdaptor as explained with some code examples in my answer on Stackoverflow and also below.

It works, which is nice. Still trying to figure out why it works though.

If anyone has any deeper understanding of this, feel free to post here. I really would like to understand.

So, before, I had this:

Code Block swift
@main
struct MyApp: App {
var someClass = SomeClass()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
print("active")
someClass.doSomethingThatWouldNotWorkBefore()
case .background:
print("background")
case .inactive:
print("inactive")
@unknown default:
print("default")
}
}
}
}


And after the bugfix, the working solution:

Code Block swift
import SwiftUI
class AppDelegate: UIResponder, UIApplicationDelegate {
var someClass = SomeClass()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
someClass.doSomethingThatWouldNotWorkBefore()
return true
}
}
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
print("active")
case .background:
print("background")
case .inactive:
print("inactive")
@unknown default:
print("default")
}
}
}
}


I've not real understanding of what could occur here. Just some guessing.

Could it be you get access to different resources (or lack some) when running from the iPhone as compared as from Xcode ? Or different versions of some packages ?

Could you also check what are the mode in each case (debug ? release ?). And try to change.

Did you contact DJI about their toolkit ?

Otherwise, you could try to contact developers support or burn a DST ticket if you do not get further info on this forum.

Good luck.
One more additional observation:
  • I remove the app completely from the phone,

  • then start it again from Xcode

  • I acknowledge the dialogs that ask permission for Bluetooth and Location usage, which I want.

Then the app will again not react and stay in its initial state.

Only when I restart again via Xcode the connection icon gets green and the video feet is being shown.




I do advise to contact DJI about their toolkit, if they ever answer.
Yes, I did contact DJI:
  • Sending dev support an email

  • Posting in their dev support forum

  • Opening an issue in the corresponding Github repo

Let's hope that at least one will lead to success.

I have also opened a DST with Apple.


How can I check which configuration is being used
  • when app is started from Xcode

  • when app is started directly from the phone ?

Is there a difference? The binary (IPA) itself should be the same, but yes, maybe some configuration and/or assets might be different.

But where to check?
Good move.

Thanks to feedback if you get something.
There will certainly be something to learn from your case.

How can I check which configuration is being used

In Xcode, at the top, at left, you'll see the name of your app, with the name of a simulator or your iPhone oat its right.

Click on the name of app to get a popup and select Edit scheme.
Check what is the build configuration.
I have looked there before, but could not find anything that would indicate any difference on how the app runs according from where it has been started.

The question that comes up when I look at the "Run"-configuration: When started from Xcode, does it use the "Debug"-config and when started directly form the phone is it then using the "Release"-config?
I have made an observation: After restarting my phone and then starting the app directly by tapping the app icon everything works as it should: the app starts, gets connected to the drone, the connection icon turns green and the camera feed is being updated as well. I was able to repeat this several times.
Accepted Answer
Finally, it works!

I had to re-introduce the AppDelegate with @UIApplicationDelegateAdaptor as explained with some code examples in my answer on Stackoverflow and also below.

It works, which is nice. Still trying to figure out why it works though.

If anyone has any deeper understanding of this, feel free to post here. I really would like to understand.

So, before, I had this:

Code Block swift
@main
struct MyApp: App {
var someClass = SomeClass()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
print("active")
someClass.doSomethingThatWouldNotWorkBefore()
case .background:
print("background")
case .inactive:
print("inactive")
@unknown default:
print("default")
}
}
}
}


And after the bugfix, the working solution:

Code Block swift
import SwiftUI
class AppDelegate: UIResponder, UIApplicationDelegate {
var someClass = SomeClass()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
someClass.doSomethingThatWouldNotWorkBefore()
return true
}
}
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
print("active")
case .background:
print("background")
case .inactive:
print("inactive")
@unknown default:
print("default")
}
}
}
}


Different behaviour when starting app from Xcode than from iPhone
 
 
Q