Thursday, 18 December 2014

Resymbolicating crash reports for iOS

Resymbolication in Xcode 6.1

  • Get the crash report from Device via Xcode

  • From the crash report get the version of the app.
  • Get the IPA and dSYM file for the version from ios-ci.
  • Put the following in a common folder (named lets say XYZ, which should not be in /tmp):
    • The unsymbolicated crash report.
    • The binary extracted from the IPA.
    • The dSYM file for the related binary.
  • On the terminal now, execute the following command:
    DEVELOPER_DIR=`xcode-select -print-path` /Applications/ -v -o resymbolicated.crash crashreport.crash
  • This should symbolicate your crash report and export the unsymbolicated version to resymbolicated.crash

Possible error case:

The whole file might not get symbolicated even with a successful run.
The verbose output in that case should end with something like:
Running /Applications/ -arch armv7 -l 0x91000 -o '/Users/ayushgoel/Downloads/11/Talkto' 0x001a3d44 0x0034f262 0x001188be 0x0031d23a 0x000978e2
Here symbolication of only 5 addresses has been tried. But in the crash report there are more addresses, which needed to be symbolicated. See code below.
Thread 5 name:  Session Background Thread  Dispatch queue: NSPersistentStoreCoordinator 0x166a8420
Thread 5 Attributed:
0   libsystem_kernel.dylib          0x338e6324 0x338e4000 + 8996
1   libsqlite3.dylib                0x335a31a0 0x3359c000 + 29088
2   libsqlite3.dylib                0x335bb7fe 0x3359c000 + 129022
3   libsqlite3.dylib                0x335ba720 0x3359c000 + 124704
4   libsqlite3.dylib                0x335d558e 0x3359c000 + 234894
5   libsqlite3.dylib                0x335dbab0 0x3359c000 + 260784
6   libsqlite3.dylib                0x335d5670 0x3359c000 + 235120
7   libsqlite3.dylib                0x335cb4aa 0x3359c000 + 193706
8   libsqlite3.dylib                0x335c9ed6 0x3359c000 + 188118
9   CoreData                        0x257ffab8 0x257ea000 + 88760
10  CoreData                        0x257ff7ae 0x257ea000 + 87982
11  CoreData                        0x258e72b2 0x257ea000 + 1036978
12  CoreData                        0x25805f0e 0x257ea000 + 114446
13  CoreData                        0x25805894 0x257ea000 + 112788
14  CoreData                        0x258b2520 0x257ea000 + 820512
15  CoreData                        0x258b97c8 0x257ea000 + 849864
16  libdispatch.dylib               0x338127a4 0x33811000 + 6052
17  libdispatch.dylib               0x33819ac4 0x33811000 + 35524
18  CoreData                        0x258ad302 0x257ea000 + 799490
19  CoreData                        0x25805512 0x257ea000 + 111890
20  CoreData                        0x258041da 0x257ea000 + 106970
21  Talkto                          0x0030fd0c 0x91000 + 2616588
22  Talkto                          0x0030f92e 0x91000 + 2615598
23  Talkto                          0x0030f9a2 0x91000 + 2615714
24  Talkto                          0x0011de7a 0x91000 + 577146
25  Talkto                          0x0011dce6 0x91000 + 576742
26  Talkto                          0x0013b77e 0x91000 + 698238
27  Talkto                          0x00128722 0x91000 + 620322
28  CoreFoundation                  0x25b00b10 0x259f6000 + 1092368
29  CoreFoundation                  0x25a2d690 0x259f6000 + 226960
30  Talkto                          0x00128324 0x91000 + 619300
31  Talkto                          0x0012769a 0x91000 + 616090
32  Talkto                          0x00127422 0x91000 + 615458
33  Talkto                          0x00126ea4 0x91000 + 614052
34  Talkto                          0x0030d2ee 0x91000 + 2605806
35  Talkto                          0x00126de2 0x91000 + 613858
36  Talkto                          0x00125fca 0x91000 + 610250
37  Talkto                          0x00311458 0x91000 + 2622552
38  Foundation                      0x2680cd6a 0x2673c000 + 855402
39  CoreFoundation                  0x25ac2d54 0x259f6000 + 838996
40  CoreFoundation                  0x25ac2162 0x259f6000 + 835938
41  CoreFoundation                  0x25ac07c8 0x259f6000 + 829384
42  CoreFoundation                  0x25a0e3bc 0x259f6000 + 99260
43  CoreFoundation                  0x25a0e1ce 0x259f6000 + 98766
44  Foundation                      0x26747bf8 0x2673c000 + 48120
45  Talkto                          0x000ebc42 0x91000 + 371778
46  Foundation                      0x2680cb56 0x2673c000 + 854870
47  libsystem_pthread.dylib         0x33975e90 0x33973000 + 11920
48  libsystem_pthread.dylib         0x33975e02 0x33973000 + 11778
49  libsystem_pthread.dylib         0x33973b8c 0x33973000 + 2956

This is because of the faulty parsing by the script.
To fix this convert: Thread 5 Attributed: -> Thread 5:.
And now run the script again to see the magic!

Friday, 28 November 2014

iOS 8.2 makes the view property of UIViewController an implicitly-unwrapped optional

Refer: API-Diff

This change documents the fact, that view should not be accessed until a UIViewController's viewDidLoad() method is called. Accessing the view of a UIViewController before it was loaded causes an NSInternalInconsistencyException.

Wednesday, 26 November 2014

Notes for Core Data

* Use performBlock to do tasks on NSManagedObjectContext

* Three types of concurrency available for NSManagedObjectContext
  - Main thread linked to UI (NSMainQueueConcurrencyType)
  - Private queue for background tasks (NSPrivateQueueConcurrencyType)
  - Confinement for legacy (NSConfinementConcurrencyType)

* NSConfinementConcurrencyType
  - used with 
    - serialised dispatch_queue or
    - NSOperationQueue with max concurrency one
  - harder to manage

* To simplify usage of Core Data APIs, use NSMainQueueConcurrencyType
  - View controllers and other UI components can use directly and are not required to know about performBlock: APIs.

* NSManagedObject owned by NSManagedObjectContext it was created in
  - Access allowed in only the NSOperationQueue (or dispatch_queue) the related NSManagedObjectContext is related to.
  - Use objectID of NSManagedObject to pass around objects.

* New in iOS 8 to check (advanced use):
  - NSBatchUpdateRequest
  - NSAsynchronousFetchRequest - returns immediately and on completion, runs the given block

Thursday, 16 October 2014

Use Sublime text 2 to build python 3 files

Go to Tools > Build System > New Build System...

Now, copy the following JSON to it:

{  "cmd" : ["/usr/local/bin/python3", "-u", "$file"]}

Remember to put the complete path for you python program.
Save the file with name "MyPython.sublime-build"

To get a file, to be build by this new build system:

  1. Open
  2. Go to Tools > Build System , and choose MyPython from the list.
  3. Select Tools > Build, or press ⌘B
Happy coding! 

Friday, 29 August 2014

Linking File's owner in a Nib

Yes, nibs are old now, but once in a while, I like to use them when the storyboard view controller starts growing too much.

Recent issue with me was linking my IBActions to UIButtons in the Nib. The file owner was not showing me the options, nor could I Ctrl+drag the IBActions directly to my view controller.

Supposedly the problem lied in the fact that Xcode by default makes the File Owners class as NSObject. Changing the class for the owner to `MyClass` fixed the issue.

Saturday, 17 May 2014

Getting lldb python module on Mac OS X

I was recently browsing lldb seeing that I had access the the awesome world of lldb (our very own debugger) via a python module and I could create custom lldb functions usable in Xcode directly.

But when I tried to check out the module, my python installation could not find the module!

The problem is simple, the module is not present in my `$PYTHONPATH`. Searching around a bit I gathered that the lldb module is a property of Xcode and thus is ported with the app itself. The path to the module is 
Now, the other issue, was how do I add this to my `$PYTHONPATH`. It would be outrageous to add a line on top of my every python script that fixes the `$PYTHONPATH` for me. The solution was in `~/.pythonrc`. I added the following code to my`~/.pythonrc` :

Voila! It is done! Now whenever I fire up python, `~/.pythonrc` is executed first, thus changing (fixing) the  `$PYTHONPATH` for every script of me.

Note : chisel is a great source of information on how things work and would work regarding the lldb python module.

  1. - lldb python reference
  3. - .pythonrc reference
  4. - a collection of LLDB commands to assist debugging iOS apps by facebook. 

Thursday, 27 March 2014

Box all your numbers in new literal syntax with find and replace

Xcode provides no shortcut to box your variables to use new literal syntax, and doing it by hand is seriously time taking.

A small approach to help is to use the "Find and Replace" option of Xcode (⌘ + ⌥ + F).

What to find? : Any word
What to replace with? @( matched word )

How to do it? with magic.. ;)
Use \1 in your replacement string to get the matched word.
Note: On Xcode 6+, Use $1 instead.

See the screenshot below. Hope this helps.

For Xcode 6+, 

If you have used any other solutions, please share them in comments.

Tuesday, 11 March 2014

Ask user to allow access to his address book

This code refers to ONLY asking for the address book permission and not doing any related manipulation. The code has been tested for iOS 7.

Note: If ABAddressBookGetAuthorizationStatus() returns a value other than kABAuthorizationStatusNotDetermined, NO access alert is shown.

Possible values from ABAddressBookGetAuthorizationStatus() is given by:


Tuesday, 11 February 2014

Vim configuration

To change your vim configuration, change ~/.vimrc .
Here are the contents of my ~/.vimrc :

Sunday, 9 February 2014

Sync any application managed folder to your cloud storage

Applications for services like Dropbox and Box allow you to have a local folder that they sync with your cloud regularly.
For example for Dropbox on my computer it is :

Recently I wanted to sync all the music managed by iTunes on my mac to my dropbox folder. iTunes keeps all my music in the folder :

Now the problem was that if I copied my Music/ folder to Dropbox/ folder

  • It would have taken up double space on my disk 
  • Any new additions or deletions to my music library would not reflect to my cloud storage automatically. I would have to explicitly copy all changes to Dropbox/ folder.
The solution lies in symlinks. Read more on Wikipedia about symlinks here. 
In short, symlinks are like pointers to a file. They just point, and thus solve both of the above problems. They only take the space required by the symlink itself and no extra file storage is used. Also, any new changed to linked folder are reflected by the link too.

So to create a link to the Music/ folder in Dropbox/ folder all I do is execute the following statement in my terminal :