简体   繁体   English

iOS应用程式因错误而当机:NSCFNumber stringByReplacingOccurrencesOfString:withString:无法识别的选择器已传送至执行个体

[英]iOS app crashing with error: NSCFNumber stringByReplacingOccurrencesOfString:withString: unrecognized selector sent to instance

Our iOS app terminates with an error of [__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090 . 我们的iOS应用终止于错误[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090

We're testing on an iPhone 5 w iOS 7. 我们正在使用iOS 7的iPhone 5进行测试。

It crashes on this line: [self parseDictionary:notificationMessage intoJSON:jsonStr] . 它在以下行崩溃: [self parseDictionary:notificationMessage intoJSON:jsonStr]

Method containing this line: 包含此行的方法:

- (void)notificationReceived {
    NSLog(@"Notification received");

    if (notificationMessage && self.callback)
    {
        NSMutableString *jsonStr = [NSMutableString stringWithString:@"{"];

        [self parseDictionary:notificationMessage intoJSON:jsonStr];

        if (isInline)
        {
            [jsonStr appendFormat:@"foreground:\"%d\"", 1];
            isInline = NO;
        }
        else
            [jsonStr appendFormat:@"foreground:\"%d\"", 0];

        [jsonStr appendString:@"}"];

        NSLog(@"Msg: %@", jsonStr);

        NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", self.callback, jsonStr];
        [self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];

        self.notificationMessage = nil;
    }
}

-(void)parseDictionary:(NSDictionary *)inDictionary intoJSON:(NSMutableString *)jsonString
{
    NSArray         *keys = [inDictionary allKeys];
    NSString        *key;

    for (key in keys)
    {
        id thisObject = [inDictionary objectForKey:key];

        if ([thisObject isKindOfClass:[NSDictionary class]])
            [self parseDictionary:thisObject intoJSON:jsonString];
        else
            [jsonString appendFormat:@"\"%@\":\"%@\",",
             key,
             [[[[inDictionary objectForKey:key]
               stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]
                stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]
                stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]];
    }
}

Stack trace (along with one debugging line to show the variable value): 堆栈跟踪(以及一条调试行以显示变量值):

2014-01-07 16:32:36.980 Wopple[195:60b] Notification received
Printing description of self->notificationMessage:
{
    "_" = "gHf8EeO3_ZDiugJkgA";
    aps =     {
        alert = "hi foo bar right";
        badge = 3;
    };
}
2014-01-07 16:33:22.774 Wopple[195:60b] -[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090
2014-01-07 16:33:22.776 Wopple[195:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090'
*** First throw call stack:
(0x308c3e83 0x3ac246c7 0x308c77b7 0x308c60af 0x30814dc8 0x88da5 0x88d1f 0x88915 0x8757b 0x3335ec93 0x3335f75d 0x340d0b37 0x3088e777 0x3088e713 0x3088cedf 0x307f7471 0x307f7253 0x3552b2eb 0x330ac845 0x7f5d3 0x3b11dab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

When you're using: 使用时:

[[[[inDictionary objectForKey:key]
               stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]
                stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]
                stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]];

You're assuming that objectForKey is going to return an NSString object. 您假设objectForKey将返回一个NSString对象。 But, in the case where your app is crashing, the object returned is actually an NSNumber . 但是,在您的应用崩溃的情况下,返回的对象实际上是一个NSNumber

You should use isKindOfClass: to determine the object type, or use stringValue on your NSNumber to get a string representation of the object. 您应该使用isKindOfClass:确定对象类型,或者在NSNumber上使用stringValue获取对象的字符串表示形式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的iPhone应用程序崩溃并显示[__NSCFDictionary stringByReplacingOccurrencesOfString:withString:]:无法识别的选择器已发送到实例 - My iPhone app is crashing and showing [__NSCFDictionary stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance ios [__NSCFNumber length]:无法识别的选择器已发送到实例 - ios [__NSCFNumber length]: unrecognized selector sent to instance 目标C错误[__NSCFNumber长度]:无法识别的选择器已发送到实例 - Objective C error [__NSCFNumber length]: unrecognized selector sent to instance 调用sizeToFit时,ios应用崩溃,无法识别的选择器发送到实例 - ios app crashing with unrecognized selector sent to instance when sizeToFit is called [NSCFNumber isEqualToString:]:发送到实例的无法识别的选择器 - [NSCFNumber isEqualToString:]: unrecognized selector sent to instance UILocalizedIndexedCollat​​ion-[__ NSCFNumber length]:无法识别的选择器已发送到实例 - UILocalizedIndexedCollation -[__NSCFNumber length]: unrecognized selector sent to instance Flurry在恢复后台线程时崩溃iOS [__NSCFNumber length]:无法识别的选择器发送到实例0xb000000000c58913 - Flurry Crashing iOS When Resuming Background Thread [__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000c58913 -[__ NSCFNumber行]:无法识别的选择器已发送到实例 - -[__NSCFNumber row]: unrecognized selector sent to instance [__NSCFNumber长度]:无法识别的选择器已发送到实例 - [__NSCFNumber length]: unrecognized selector sent to instance 应用程序因错误而崩溃:-[NSNull 长度]:无法识别的选择器发送到实例 - App crashing with error: -[NSNull length]: unrecognized selector sent to instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM