Swift application quits after open, works from Xcode - ios

I am encountering a strange situation with a simple application I develop. When I deploy the application using Xcode (with debugger attached), it works perfectly.
When I close Xcode, disconnect the phone, kill and restart the application, it works just fine, too! For several hours that is.
After some time (usually the next day morning) when I try to open the app up, it immediately fails. A white rectangle filling the screen animation does happen, but when the application is supposed to flash its UI in, it quits instead.
How can I get ahold of the crash logs from the iPhone? Does it store any? This application is not from the AppStore, it's my development application installed through Xcode.
When I re-deploy it after finding this has happened again, hoping I'll get something with a debugger attached, it starts working again. This has happened to two of my apps.

You could try to look into your device's logs: Window->Devices -> Select your device-> Click 'View Device Logs'. Find your app crash there and on the right side you should see a crash report.

Related

How to debug react-native iOS app crashing on startup after a week or so

I started messing around with react-native. I've built a small application and it seems to work fine (package.json). I can work on it in Debug or Release mode, using the simulator or my iPhone 6S device, and all is well.
This app is just for me so I don't pay for the Apple Developer thing, and I just run the app in Release mode on my device, and it...seems to be fine? I can quit xcode and go places and the app works fine.
After a week or so, it's hard to tell, the app stops loading. It'll display the splash screen for a split second and then it's gone back to the home screen.
I setup Rollbar, but it doesn't catch anything. I look in the Privacy -> Analytics area and don't see anything there either.
I'm not really looking for an answer to my exact problem since various SO questions and other places suggest it's probably something weird and specific. My main problem is I don't know even where to look/how to debug this kind of thing. If I build the app and run it on device again, it'll run fine. I need to try to debug without loading new code, and have no idea how that works on iOS. I've tried poking around at the Debug -> Attach to Process by Name, but the app never gets far enough to do anything with that.
Alternatively, I throw react-native in the garbage and use something that works...
App provisioning with a free developer license (?) is 7 days. See: Why does my free XCode Provisioning Profile only last 7 days?
You can likely verify this by looking at error messages in the console window. Connect your device, and in Xcode go to Window/Devices and Simulators/Open Console, then launch your app.

App freezes several seconds before start on device

I'm a free developer and I use my swift application on my iPhone 7. I'm using Swift 3 and iOS 10.
So the problem is, sometimes (like 2 of 10 times) when I start the app, iOS freezes like 5 seconds before my app actualy comes to the screen. In this time I only see the app icon is in the highlighted state. This only happens with my own app, not with other apps.
My app also does nothing special on startup and this only happens on the real device, the debugger in Xcode always starts immediately.
So is this a normal behavior? And does it work properly when I decide to put it on the App Store?
Thanks in advance.
I have had this happen to me before. No, this does not happen when it is put out on the App Store. One way to get around this is to use TestFlight. You can upload your archive to apple and select on the 'TestFlight' tab of your app. Click on internal testing and then click on your email and the version of the app you want to test. You should then get an email on your Apple ID telling you to test the app, and it will let you download it. Good question :)
To test the same version which would have been uploaded to the store quickly, change the build configuration to release. To do so, click on your app's name (top left), press edit schema, click the build configuration dropdown, also deselect debug executable. (make sure to turn it back when you're going to debug, or create a new schema with the above settings to let you switch quickly in the future)
You might also try using instruments, that lag on startup might happen if you're trying to load many things in memory on your initial view controller's viewDidLoad or app delegate's didFinishLaunchingWithOptions load, especially when trying to load big files such as images, videos or large plists. You might want to try using instruments (the time profiler instrument specifically) in order to check it out.

My WatchOS2 app stuck on launch with Spinner

I built a demo app on WatchOS 2.0.1, on every launch it was getting stuck with App name on Top Left corner and spinner in middle of screen on iWatch (38mm). Watch is brand new and have only native apps installed till now so there should not be any issue with memory.
I tried many times to open the app but it was repeatedly closing automatically after showing Spinner for sometime. After lots of trial my Apps screen got visible and then after on every launch it worked fine without sticking on launch. I tried to double check by Force quit my app using Power button but it worked fine then after.
Then I uninstalled the app from watch and reinstalled it and same thing happened again. It started sticking. Do anyone have Idea on this? Please help on this part.
WatchOS Version : 2.0.1
Your app is crashing, as evidenced by it "automatically closing."
You should be able to track down the reason for the crash by examining the crash report (which can be found in the Xcode Window -> Devices pane). Alternately, you should be able to interactively debug this by running the app within Xcode.
As for it eventually no longer crashing until you deleted and reinstalled the app, the app reached a state where the reason for the crash no longer occurred. This probably is related to needing to handle some error pertaining to a path or file which it is finally able to create or access. Deleting the app recreated the condition where it repeatedly crashed again.

See logs before & after app restart

I have my iPhone app running on device, I can see logs in xcode.
Then, I what to see logs about what is happening when app restart.
So, I press home button twice -> swipe up to stop my app, then launch the app again. But I can't see any log in xcode anymore.
How can I see logs of my app continuously before & after my app restart in xcode?
==== UPDATE ===
I mean app log. OK, I can narrow my question to: How can I see logs again after I restarted my app? (device is connected to my mac book , I saw app logs in xcode before restarting, but can't find a way to see app logs after I restarted my app).
You can't see logs of an app that is not running. I can tell you this if you're really curious : there is nothing to log anyway. :)
Now you might want one of those things :
System logs :
Just go in the Device Manager of XCode (short cut is Shift-Apple-2 I think). It's in the Window Tab, under Devices. Select the device you're running on, then you'll have the logs available there.
This logs everything the device logs, so there will be a LOT of text.
App logs :
Those are the ones you already have, but you seem to clearly want the "restart" logs of your app. There is no such thing as a restart log. What you have is the logs at the start of your app, and the ones at the end. For example, what you logged in your AppDelegate's didBecomeActive or willTerminate (or even didEnterBackground).
You will only see the logs of the didBecomeActive when you actually run the app from XCode (otherwise the debugger is offline). He will start the app as if you tapped on the app icon, so no worries there.
If you decide to kill the app by swiping up, it will log the app delegate, and you'll just be able to browse it in the debugger. You can put a breakpoint if you want to make sure it enters the AppDelegate methods.
But if you want to restart the app again, you'll have to re-run it from Xcode, not manually start it on the phone.
File logging :
Another very easy solution is to log everything on a text file in the Documents directory of your app, you'll then be able to start/quit as much as you want, and let it log on the file. You can later read that file like any other file :)
In case you want to just show the device logs you may want to take a look at this answer:
https://stackoverflow.com/a/19148654/691977

iOS: Simulating user quitting app

I just added persistent data into my app and wanted to test it with my iPhone. When I quit my app (double tap home and swipe up), I'm unable to open it again (the icon freezes). When I try the same thing on the iOS simulator in Xcode, it crashes too. I get a SIGTERM error coming from my AppDelegate. Is this what is supposed to happen when the user quits while testing, or is this an issue with my data? Is there any way to simulate the user quitting and restarting the app to make sure my data is still there?
Thanks
This is not what is supposed to happen when the user quits while the Xcode debugger is attached (at least not anymore — this question is a couple years old after all).
If you force quit an app while running from Xcode (whether simulator or on a physical device) it just stops the debugger and you should be able to relaunch it without issue. The Xcode debugger will not be attached when you launch like that, but from Xcode you can attach the debugger to an existing process (Debug > Attach to Process).
Note, if run in Xcode and then you quit the simulator application on your Mac (or close the simulator's window) then you will get a SIGTERM error in main.swift. But this is not the same as a user terminating your app, nor is it comparable to a user turning off their device.
From what you're describing it sounds like there is a bug in your code that is causing it to freeze when launching when the debugger is detached or when it's relaunching after termination.
To simulate the user quitting and restarting you should be able to terminate the app from your device/simulator, and then either run it again from Xcode or launch it from the device/simulator and attach to the process from Xcode.
In some cases it may be helpful to put in some debugging code that pops up an alert / update some label at runtime to indicate the data persisted properly after the app re-launched so that you don't always have to have Xcode attached to diagnose problems in your app.
This is the correct behavior if you are running the app from Xcode. However, once you've uploaded/run the app once, you can test closing and reopening it. Simply stop the run in Xcode, go to your phone or simulator, and click on the app icon to open it. Unfortunately, you won't have a debugger log at that point, but you can see if your data persists.

Resources