Ios application error on startup

I started using crashlytics for my iphone application and it seems to crash for some users during startup (or what I assume is startup). Here is the stack trace:

Fatal Exception: NSInvalidArgumentException
-[NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x19687eba0
Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x00000001854aa59c __exceptionPreprocess + 132
1  libobjc.A.dylib                0x0000000195bfc0e4 objc_exception_throw + 60
2  CoreFoundation                 0x00000001854b1664 __methodDescriptionForSelector
3  CoreFoundation                 0x00000001854ae418 ___forwarding___ + 928
4  CoreFoundation                 0x00000001853b2b6c _CF_forwarding_prep_0 + 92
5  UIKit                          0x0000000189fc38a0 -[UILabel _contentInsetsFromFonts] +    104
6  UIKit                          0x000000018a13ac90 -[_UILabelLayer updateContentInsets] + 76
7  UIKit                          0x000000018a13ad50 -[_UILabelLayer updateContentLayerSize] + 56
8  UIKit                          0x000000018a13ae34 -[_UILabelLayer layoutSublayers] + 36
9  QuartzCore                     0x00000001895ac564    CA::Layer::layout_if_needed(CA::Transaction*) + 320
10 QuartzCore                     0x00000001895ac408 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
11 QuartzCore                     0x00000001895abc08 CA::Context::commit_transaction(CA::Transaction*) + 276
12 QuartzCore                     0x00000001895ab98c CA::Transaction::commit() + 436
13 QuartzCore                     0x00000001895a53bc CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
14 CoreFoundation                 0x0000000185462a50 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
15 CoreFoundation                 0x000000018545f9dc __CFRunLoopDoObservers + 360
16 CoreFoundation                 0x000000018545fdbc __CFRunLoopRun + 836
17 CoreFoundation                 0x000000018538d0a4 CFRunLoopRunSpecific + 396
18 GraphicsServices               0x000000018e52f5a4 GSEventRunModal + 168
19 UIKit                          0x0000000189cc23c0 UIApplicationMain + 1488
20 partybutton                    0x00000001000d6de0 main (main.m:16)
21 libdyld.dylib                  0x000000019626aa08 start + 4

Not sure how to debug this, as I cannot reproduce it myself. Any pointers?

+4
source share
6 answers

I have the same problem. The sever JSON response contains NULL / null. Something like that:

"result":[
    {
        "id":"44",
        "message":null,
    }]

I created a class category NSNull. Then methods NSStringthat throw exceptions are added .

NSNull + JSON.h file:

#import <UIKit/UIKit.h>

@interface NSNull(JSON)

@end

NSNull + JSON.m file:

@implementation NSNull (JSON)

- (NSUInteger)length { return 0; }

- (NSInteger)integerValue { return 0; };

- (float)floatValue { return 0; };

- (NSString *)description { return @"0(NSNull)"; }

- (NSArray *)componentsSeparatedByString:(NSString *)separator { return @[]; }

- (id)objectForKey:(id)key { return nil; }

- (BOOL)boolValue { return NO; }

- (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)aSet{
    NSRange nullRange = {NSNotFound, 0};
    return nullRange;
}

//add methods of NSString if needed

@end

This way, I do not need to check for NULL in every variable.

+13

JSON, , NULL String, Json parsing , iOS .

+2

kazi.munshimun, NSDictionary . NULL.

GitHub: NSDictionary

0

[NSNull rangeOfCharacterFromSet:] User Defined Runtime Attributed,

0

IOS NULL , . , json NSNULL

NSString * yourVariable = ([stringVariable isEqual: [NSNull null]])? @"": stringVariable;

0

an easy way is to check    NSString *city= set value from json ;for example

then check →

NSString *city=[responseDictionaryForEachRow     valueForKey:@"City"];
if (![city isKindOfClass:[NSNull class]]){
    @"Your code if string is not null";`
}
0
source

All Articles