Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString cont

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFString containsString:]: unrecognized selector sent to instance
Crash原因:NSString 的containsSTring:方法是在iOS8.0 之后的方法,这边因为产品是适配到7.0,所以iOS设备的版本在8.0以下使用不了,自然就会奔溃。
Crash日志截图:
crash

crash部分日志如下:
Incident Identifier: ****
CrashReporter Key: A867AD01-C641-4BFC-8665-2B509C01817A
Hardware Model: iPhone4,1
Process: Light [935]
Path: *****
Identifier: ***
Version: 201601011
Code Type: ARM
Parent Process: launchd [1]
Date/Time: 2016-01-12T02:11:27Z
OS Version: iPhone OS 7.1.2 (11D257)
Report Version: 104
Exception Type: SIGABRT
Exception Codes: #0 at 0x39fed1f0
Crashed Thread: 0
Application Specific Information:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFString containsString:]: unrecognized selector sent to instance 0x145518b0’
Last Exception Backtrace:
0 CoreFoundation 0x2f1aff83 130
1 libobjc.A.dylib 0x39a2accf objc_exception_throw 38
2 CoreFoundation 0x2f1b3917 -[NSObject doesNotRecognizeSelector:] 202
3 CoreFoundation 0x2f1b2203 706
4 CoreFoundation 0x2f101768 _CF_forwarding_prep_0 24
5 Light 0x000a349b 0x2d000 484507
6 Light 0x00072d35 0x2d000 286005
7 CoreBluetooth 0x2eed6beb -[CBPeripheral handleAttributeEvent:args:attributeSelector:delegateSelector:] 286
8 CoreBluetooth 0x2eed6ccf -[CBPeripheral handleCharacteristicEvent:characteristicSelector:delegateSelector:] 74
9 CoreBluetooth 0x2eed6dd1 -[CBPeripheral handleCharacteristicValueUpdated:] 52
10 CoreBluetooth 0x2eed2fab -[CBCentralManager xpcConnection:didReceiveMsg:args:] 122
11 CoreBluetooth 0x2eedb64b 78
12 libdispatch.dylib 0x39f12833 10
13 libdispatch.dylib 0x39f1281f 22
14 libdispatch.dylib 0x39f1949f 278
15 CoreFoundation 0x2f17a8a1 8
16 CoreFoundation 0x2f179175 1300
17 CoreFoundation 0x2f0e3ebf CFRunLoopRunSpecific 522
18 CoreFoundation 0x2f0e3ca3 CFRunLoopRunInMode 106
19 GraphicsServices 0x3403d663 GSEventRunModal 138
20 UIKit 0x31a3014d UIApplicationMain 1136
21 Light 0x00160ccd 0x2d000 1260749
22 libdyld.dylib 0x39f37ab7 2

解决方法:这边我写了个类扩展containsString,

具体代码如下:
NSString+containsString.h
//
// NSString+containsString.h
// TJJ_NSStringContainsStringDemo
//
// Created by Shixiongwei on 16/1/21.
// Copyright © 2016年 Shixiongwei. All rights reserved.
/*
NSString 的containsString方法,是iOS8 之后的方法。
这个扩展类,是向下兼容 使得iOS8 一下的方法能使用containsString方法。
NSString 的内扩展 containsString方法。
亲测:iOS7.1.1 能用。
*/

“import Foundation/Foundation.h”

@interface NSString (containsString)
- (BOOL)containsString:(NSString *)str NS_AVAILABLE(10_10, 8_0);
@end

NSString+containsString.m
//
// NSString+containsString.m
// TJJ_NSStringContainsStringDemo
//
// Created by Shixiongwei on 16/1/21.
// Copyright © 2016年 Shixiongwei. All rights reserved.
//

import “NSString+containsString.h”

@implementation NSString (containsString)
- (BOOL)containsString:(NSString *)str NS_AVAILABLE(10_10, 8_0)
{
if ([self rangeOfString:str].location != NSNotFound) {
return YES;
}
return NO;
}
@end

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值