启动时ios应用崩溃 [英] ios app crash on startup

查看:1233
本文介绍了启动时ios应用崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用crashlytics为我的iphone应用程序,它似乎崩溃了一些用户在启动期间(或我猜猜是启动)。这是堆栈跟踪:

I started using crashlytics for my iphone app, and it seems that it crashes for some users during startup (or what I am guessing 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 really sure how to debug this since I cannot reproduce on my own. Any pointers?

推荐答案

我有类似的问题。来自服务器的JSON响应包含NULL / null。像这样:

I have similar kind of problem. JSON response from sever contains NULL/null. Something like this:

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

NSNull 类。然后添加引起异常的 NSString 方法。

I created a category of NSNull class. Then added the methods of NSString that causing the exceptions.

NSNull + JSON.h文件:

NSNull+JSON.h file:

#import <UIKit/UIKit.h>

@interface NSNull(JSON)

@end

NSNull + JSON.m档案:

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

通过这样做,我不必在每个变量中检查NULL。

By doing this I do not have to check NULL in every variable.

这篇关于启动时ios应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆