Code To Crush A Swift Application on Startup/launch - swift

In an Xcode project, how can I write any Swift codes that crashes the Application on startup once it’s launched/run on the simulator or device?

You can follow app lifecycle events in your UIApplicationDelegate. For example application(_:didFinishLaunchingWithOptions:)) is called, when the app started and a little time before it's visible. You can put the crashing code there.
There are a few ways to crash the app. One of them is to call fatalError().

Related

BLE wasn't working in the background under iOS9

I'm a long-time lurker at Stack Overflow, and joined up today just to post a solution to a problem that has vexed me for weeks, for which I haven't seen the solution anywhere else. Maybe someone else will be helped.
We have an iOS app written in Swift that uses a vendor-supplied SDK to communicate with a specific BLE device. The problem was that iOS would pause the app when it moved into the background rather than leave it running, but would only do this under iOS9. Under iOS10 & 11, everything worked fine in the background.
At first I figured the vendor needed to tweak their SDK code, but their sample application worked fine in the background on iOS9.
Cutting to the chase: our app was instantiating the BLE worker class from within AppDelegate, since it needs to run independently of whatever view is currently displayed on the screen. It finally dawned on me that the biggest difference between our app and the vendor's sample app was that they instantiated the BLE scanning, etc., from within a view controller class.
I modified the code to instantiate the BLE worker object from within the viewDidLoad event of the first view controller, and then set a reference to it in AppDelegate. That did the trick. I'm guessing that iOS9 needs the BLE code to be tied to the main UI processing thread, rather than AppDelegate, in order to know to allow the app to continue to run in the background.
So if you need to communicate with a BLE device when your app is backgrounded, and backgrounding doesn't work for iOS9 devices only, make sure you instantiate the BLE communication from within a View Controller class.

App crashes on iPhone but not simulator or iPad?

I have developed an app for the iPhone and everything is going well. Today i decided to prep it for the upcoming iOS 7 launch, and the app worked as intended until I tried it on my iPhone 5. Whenever it crashes it throws some exc_bad_access codes.
It doesn't crash in the simulator or on my iPad which is running iOS 6.1.
I hope you guys can help me.
Btw, i get different exc_bad_access codes every time, but this is one of them.
http://gyazo.com/43716488eb120e44e74f76cd4d659076
You have thread-related race conditions. Note how it's crashing in thread 7? Race conditions will express themselves differently on different hardware since the timing can be dramatically different.
tableView:cellForRowAtIndexPath: is a UIKit method that must run on the main thread. In your case, it's running on thread 7, which is itself probably the cause of your problem. I suspect you're doing something like calling reloadData on a background thread.
Note that you're also directly accessing your ivars rather than using accessors. That tends to make threading problems harder to track down and manage. You should always be using accessors except in init, inside of accessors, and in dealloc.

App Created with ios4 is crashing in ios6 and not installing

My App, which is created for iOS4, is crashing in iOS6 and is not installing on simulator or device.
It just shows the splash screen and crashes.
Did finish Launching is not being called.
Can anybody please Help?
Finally i got the solution of my problem mentioned above.
In my ios4 App, in FirstViewController.xib "Use AutoLayout" was checked.
I just removed the checkmark and my App start working.
Amazing!!!
I would recommend creating a new project, and either carefully looking for the changes in delegate or any deprecated code, or just moving all of your code to the new project. Also, you should run a convert to modern syntax check.
There may be issue with Application Delegate. The obvious reason - your object is not set as an application delegate.
Looking at Apple documentation there is quite a few ways to accomplish it:
Remove application delegate binding in Interface Builder (.xib file
for the window) Set 4th parameter of UIApplicationMain in main.h to
something else than nil.
Check you nib file in Interface Builder and see if the App Delegate is setup.
Or Reference to documentation Core Application Design
Hope this will you out.
Look into the release notes of xcode, ios6
It is said that when working with IOS6, Auto Layout is turned on and that crashes the app if used on older versions. Check the link, which has other things to watch out for:
https://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-Xcode/_index.html
https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

Flurry API crashing iPhone simulator

My app is crashing using iOS5 and iOS4.3 iPhone simulators in Xcode 4.2, the stack trace shows BAD_ACCESS signal in [FlurryAPI stopBackgroundTask] method.
While in the iOS4.3 simulator the app is only crashing when sending the app to background, in iOS5 is crashing always.I am attaching a picture of the debug navigator showing the thread where the BAD_ACCESS is happening.
On the other hand the app is working fine using a real device.
Any ideas of how can I get more information of what is going on and why this is happening?
I've worked around this issue by adding the following to didFinishLaunchingWithOptions
#if TARGET_IPHONE_SIMULATOR
[FlurryAnalytics setSessionReportsOnPauseEnabled:NO];
#endif
Flurry analytics does not run other than main Thread. It might crash on background thread.
It looks like you have a zombie - you have a situation where you're using code after you've released it. The retain count reaches zero, so the system dealloctes and re-uses the memory, then you make a change through the original reference. Now you have two different references to the same memory, each of which expects a different object to be there. In your case, one of the references is within flurry.
The reason for your device/simulator differences is the different memory allocation schemes the two architectures use - the simulator seems to re-use memory very aggressively.
Enable NSZombie and run in the debugger. If you're lucky, it will give you the object and the point it's used after deallocation.
Enable NSZombie: Menu 'Product', 'Edit Scheme...' 'Run' page, 'Diagnostics' tab, tick 'Enable Zombie Objects'.

iPhone simulator minimizes the application

I'm debugging my app with the simulator. And for some moment in concrete situation the app gets mimimized. I think there is some problem in my code (Most likely some variable is not initialized, because sometimes everything works) . But how can I catch this moment.
In xcode is still written that the program is running and I can put breakpoints and the will trigger.
And if i will reopen my application it will continue working...
When using device the are no problems too...
How can i catch this moment and pause the program to view a callstack.
EDIT
I Think the problem is here:
Objective-c singleton object does not working as expected
You could try catching it in the - (void)applicationDidEnterBackground:(UIApplication *)application-methode in the app delegate, at least then you will see specifically when it happens.