Crashing app when device not connected to Xcode - iphone

I've encountered this weird behavior with my iPhone app. It runs fine on the device when being debugged with Xcode, but when it's run on the device when the device is not connected to my computer it crashes almost immediately. Needless to say, I find this a bit disconcerting since I'm not sure how to debug it.
Anyone have ideas on what's going on or how to debug this type of problem?
I looked in the crash report when I reconnect the device and get the following:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000070
Crashed Thread: 6
Thread 6 Crashed:
0 libobjc.A.dylib 0x300102ac 0x3000c000 + 17068
1 myapp 0x000033ba 0x1000 + 9146
2 myapp 0x0000adc8 0x1000 + 40392
3 Foundation 0x30553356 0x30501000 + 336726
4 Foundation 0x305025fe 0x30501000 + 5630
5 libSystem.B.dylib 0x31d6a6ea 0x31d46000 + 149226
and the console log has the following:
Sun Sep 27 19:59:50 unknown ReportCrash[455] <Notice>: Formulating crash report for process myapp[453]
Sun Sep 27 19:59:50 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.yourcompany.myapp[0x2fba]) Job appears to have crashed: Bus error
Sun Sep 27 19:59:50 unknown com.apple.mobile.lockdown[14] <Notice>: Could not receive size of message
Sun Sep 27 19:59:50 unknown lockdownd[14] <Error>: (0x834400) handle_connection: Could not receive internal message #2 from myapp Killing connection
Sun Sep 27 19:59:50 unknown SpringBoard[23] <Warning>: Application 'myapp' exited abnormally with signal 10: Bus error
Many thanks

You can always get to the line of your app where it crash. Open the terminal on the build folder and run this command:
atos -arch armv6 -o myapp.app/myapp 0x000033ba
and it will return the file and line where it was. It's somehow useful.

Just to generalize #seppo0010's answer and update it for 2011:
First off, in Xcode4, Device Logs (found in the Organizer window) will show you the thread, file, and line number of the crash, so atos may not even be necessary. The crashes can be sorted by Application, Type, and Date/Time. A typical crash would include something like the following:
Thread 1 name: Dispatch queue: someQueue
Thread 1 Crashed:
0 MyApp 0x00003e14 -[MyAppViewController someMethod:withParam1:andParam2:] (MyAppViewController.m:254)
But if you do decide to use atos, note the following:
Be sure that you change the -arch flag to match whatever architecture your code is running on. So, for my iPhone 4, I'd enter -arch armv7.
Xcode 4 places your build path in a different place, so be sure to check in Xcode > Prefs > Locations. The path to your actual build may look something like this: /Users/OldMcStopher/Library/Developer/Xcode/DerivedData/MyApp-someUglyString/Build/Products/Debug-iphoneos
The -o flag is looking for the actual binary and not just the myapp.app wrapper, so once in the Debug-iphoneos folder (or wherever your debug .app build lives), set the -o flag to MyApp.app/MyApp, like #seppo0010 properly stated.
The atos man page describes it as follows:
The atos command converts numeric addresses to their symbolic
equivalents. If full debug symbol information is available, for
example in a .app.dSYM sitting beside a .app, then the output of atos
will include file name and source line number information.
It can be found here:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/atos.1.html
(Or with man atos from the terminal.)

Related

Today widget doesn't work outside Xcode

I successfully got a Today widget working in my iOS app. It works great when running the widget on the simulator or running on a device from Xcode. But it doesn't update if I install the app on a device and then run the widget (not from Xcode).
Has anyone else faced this issue? Is there a fix to this or is this a known bug? Any workarounds so I can have a bunch of beta testers check the app using Testflight and get the widget to work?
Using Xcode version 6.1.
Adding log statements tells me that all the correct methods are called. But after that a crash log is generated and the logs are very cryptic. This is what the console says
Dec 1 19:23:06 MyDevice ReportCrash[3592] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
Dec 1 19:23:06 MyDevice ReportCrash[3592] <Notice>: ReportCrash acting against PID 3591
Dec 1 19:23:06 MyDevice ReportCrash[3592] <Notice>: Formulating crash report for process MyTest[3591]
Dec 1 19:23:06 MyDevice SpringBoard[48] <Warning>: plugin com.testsaga.MyTest-Today interrupted
And a device log generated during this time lists this statement (specific to my widget - there are other processes in there as well)
Processes Name | <UUID> | CPU Time| rpages| purgeable| recent_max| lifetime_max| fds | [reason] | (state)
MyTest <84554d9818fe3e1fafa848c3fe6a34d5> 1.459 4132 0 - 8076 50 [per-process-limit] (frontmost)
Any insights? Thanks.
**I tried the answer here but it doesn't work for me.

App is crashing after Update Release to App store

I have released two versions of my App successfully
But after third version of app is released in App Store,when i downloaded from Appstore The App is getting Crashed :
When i try to launch app it is getting crashed immediately, and no crash reports were generated in Xcode Organizer.
The Same app is Working fine in IPAD/IPHONE SIMULATORS 5.0 and 4.1 versions
and also working fine when tested in IPHONE and IPAD devices with IOS 5.1.1 installed(run through XCODE).
No Major changes are given other than some image changes and Animation changes which are working fine when locally tested.
Please find below logs, please help to resolve this issue.
Jul 5 12:16:01 unknown fairplayd.N90[41] : libMobileGestalt computeUniqueDeviceID: total time for bb to return imei: 0 Jul 5
12:16:01 unknown SpringBoard[52] : Unable to obtain a task
name port right for pid 225: (os/kern) failure Jul 5 12:16:01 unknown
com.apple.launchd[1] :
(UIKitApplication:com.myCompany.myApp[0xdaa7]) Exited: Killed: 9 Jul
5 12:16:01 unknown com.apple.launchd[1] :
(UIKitApplication:com.myCompany.myApp[0xdaa7]) Throttling respawn:
Will start in 2147483647 seconds Jul 5 12:16:01 unknown
SpringBoard[52] : Application 'myApp' exited abnormally with
signal 9: Killed: 9 Jul 5 12:16:02 unknown kernel[0] :
AppleFairplayTextCrypterSession::fairplayOpen() failed, error -42110
Actually, this is not your fault. The App Store(s) has been having trouble as of late because it is serving corrupted binaries to consumers. Contact apple through iTunes connect for resolution, or wait a few days and release an update. To all developers reading this with pending application updates:
Wait, please wait!
Other symptoms of this include:
The app crashes immediately on launch (not even a splash screen shows, just black->crash).
Affected consumers are spread across many regions (not localized), but some are unaffected.
Your app/update has been approved fairly recently.
Mac apps will show "[App] is damaged and can't be opened. Delete [App] and download it again from the App Store."
The console will print: AppleFairplayTextCrypterSession::fairplayOopen() failed, error -42110
The only fix is to delete the app and reinstall (and basically pray for a working copy). Be assured, you are not the only one! Many major apps from huge companies are being affected by this issue (Angry Birds, NOOOOO).
Corroborated by:
http://www.marco.org/2012/07/04/app-store-corrupt-binaries
http://www.appleinsider.com/articles/12/07/04/developers_suspect_app_store_mix_up_led_to_corrupt_binaries.html
http://www.imore.com/2012/07/04/newly-installed-updated-apps-reportedly-crashing-launch-due-corrupt-app-store-binary-bug/
http://www.forbes.com/sites/anthonykosner/2012/07/05/apple-app-store-encryption-glitch-causes-many-new-app-updates-to-crash-see-list/
In your Locally tested Application Please Remove it in your Device
.After u update or download your updated app in App store

Lazy symbol binding failed: Symbol not found: _arc4random_uniform

So I programming an iOS game and I'm using arc4random_uniform for choosing a random powerup.
On the Sim, it works fine, but on my phone it throws this error (from the syslog):
Nov 26 13:44:26 iPhone ----[2184]: placePowerupCalled
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: dyld: lazy symbol binding failed: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: Referenced from: /Applications/------.app/-----
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]: Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]: dyld: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: Referenced from: /Applications/------.app/-------
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:27 iPhone ReportCrash[2185]: Formulating crash report for process -----[2184]
Nov 26 13:44:27 iPhone com.apple.launchd[1] (UIKitApplication:com.yourcompany.-----[0x1f08][2184]): (UIKitApplication:com.yourcompany.-----[0x1f08]) Job appears to have crashed: Trace/BPT trap
Nov 26 13:44:27 iPhone SpringBoard[2161]: Application '-----' exited abnormally with signal 5: Trace/BPT trap
I'm not quite sure what the problem is. I've even included the header file arc4random should come from (#include "stdlib.h"), but that hasn't worked.
Anyone have any ideas? Thanks !:)
EDIT: I tried linking binary with the "libSystem.b.dylib" library, but that didn't work either and it's still crashing from the same error.
arc4_uniform function was added in iOS 4.3 and won't run on lower versions. Looks like you run simulator on 4.3 or higher but your device has lower iOS version.
If you plan to support your app on versions lower than 4.3, try using this instead:
arc4random() % upperBoundExclusive
It might be not as precisely random as arc4_uniform, but will work.
arc4random_uniform is not available below iOS 4.3. Luckily iOS will bind this symbol at runtime and assign it to null if it's not available (hence your "lazy symbol binding" errors).
So the best way to use arc4random_uniform is to check if it's available first, like this:
#include <stdlib.h>
...
int r = 0;
if (arc4random_uniform != NULL)
r = arc4random_uniform (100);
else
r = (arc4random() % 100);

Instruments, Target Failed to run : Remote exception encountered : 'Failed to get task for pid'

I have no control over the builds. I dont have an apple dev account either. I can use a debug/checked/release build. When running test automation I continue to run into this error: Target failed to run : Remote exception encountered : 'Failed to get task for pid 506'
The automation starts, the application opens and then promptly closes. here is some console output
Oct 25 09:46:48 iphone com.apple.launchd[1] (UIKitApplication:com.something.dogfood[0xd456][504]) : (UIKitApplication:com.something.dogfood[0xd456]) Exited: Killed: 9
Oct 25 09:46:48 iphone SpringBoard[29] : Application 'MyApplicaton' exited abnormally with signal 9: Killed: 9
Any suggestions?
Instruments basically does its work by becoming the debugger for the app. Sometimes after using XCode to debug apps, I find I can't use Instruments until I reboot the device.
Unlike XCode, Instruments can be confused between two apps with the same name, but different bundle IDs. (Or perhaps same name and similar bundle IDs.) When I have multiple versions of an app on a device, I often have to delete the extra to get Instruments to connect to the correct app.
So, delete any duplicates of your app and restart the device.

GameKit on 4.0 not ready for primetime? Stopping advertising services

Gamekit applications running under 4.0 do not properly handle removing GKSession objects. Running under 3.1.3 or 3.2, if a peer disconnects and the session is cleaned up (as in Apple demos):
[gkSession disconnectFromAllPeers];
[gkSession setAvailable:NO];
[gkSession setDelegate:nil];
[gkSession setDataReceiveHandler:nil withContext:nil];
then the other peers receive state changes and a table view of peers can be updated.
In my application, one peer starts up as a server and the other starts up as a client. The client requests to connect to the server and the client's name appears in the server's list of players. If the server chooses to accept the request, the session connection is established and they can play the game. If however the client quits before the server accepts the request, the client cleans up the session (as above) and the client disappears from the server's peer list in response (when it receives a state change). This works amazingly on 3.1–3.2
When you run the same application running under 4.0 the server and client throw an error and it takes a very long time for peers to receive the state change, and when they do, the application crashes without any errors (even with NSZombieEnabled=YES in build arguments). The server never receives a "state change" message from the client. Instead, the following errors are thrown:
Thu Jul 8 23:27:26 unknown com.apple.mDNSResponder[18] <Notice>: BTLocalDeviceRemoveData: 60 byte key, 18 byte value
Thu Jul 8 23:27:26 unknown MobileBluetooth[29] <Notice>: BTLocalDeviceRemoveData - BT_ERROR_INVALID_HANDLE
Thu Jul 8 23:27:26 unknown com.apple.mDNSResponder[18] <Notice>: Call to BTLocalDeviceRemoveData failed with error 7
Thu Jul 8 23:13:39 unknown mDNSResponder[18] <Error>: external_stop_advertising_service: 18 00Z1Tud0A\\.\\.Tonberry\M-b\M^#\M^Ys\\032iPhone._1htnu3uko0uvsp._udp.local. TXT txtvers=1\M-B\M-&state=A
Thu Jul 8 23:13:39 unknown MobileBluetooth[29] <Notice>: BTLocalDeviceRemoveData - BT_ERROR_INVALID_HANDLE
With what I think is the key error:
Tue Jul 13 21:04:50 Tonberry com.apple.mDNSResponder[21] <Notice>: Call to BTDiscoveryAgentStopScan failed with error 400
Looks to me like the session is not being made unavailable (error in stopping advertising the service). The actual crash:
Thread 3 Crashed:
0 GameKitServices 0x06352f90 gckSessionChangeStateCList + 411
1 GameKitServices 0x0635b49c gckSessionRecvProc + 1474
2 libSystem.B.dylib 0x981c181d _pthread_start + 345
3 libSystem.B.dylib 0x981c16a2 thread_start + 34
I've filed a bug with my full application in progress. The app itself is done and was almost ready to submitted and runs pretty well under 3.1.3/3.2 but with the current state of Gamekit in 4.0 I can no longer submit it. Supremely disappointed and so hoping this bug report helps in the future. If anyone understands this error or what I might be doing wrong I would be supremely grateful.
Please help if you can. I'm about to throw in the towel here on this application and it's so close.
My suggestion would be to use ultimate pre-release builds of 4.1 and to report the "new" problem (either reopen the existing bug as not fixed or create a new one). That's IMHO your best bet to get the problem entirely fixed before the final release or a decent work around from Apple.
For anyone looking for help on this, I've find a workaround for the issues on 4.0.x (4.1 remedies the crashes but not the disconnect times). Just auto-accept everything. When someone requests a GameKit connection with connectToPeer:, just accept it. Don't give the user the option to select it. Disconnecting a peer from an established connection notifies the server immediately. If you leave them in just the "available" state, when they leave the connection, it will crash the server. Connect early and accept often!