iOS - [Class classMethod]导致无法识别的选择器被发送

时间:2016-02-04 09:30:48

标签: ios objective-c crash runtime unrecognized-selector

由于代码隐私,我必须省略部分信息。请原谅。

enter image description here

TokenRequestManager.m中,有一个实例方法serialQueue4TokenType

- (dispatch_queue_t)serialQueue4TokenType:(TokenType)tokenType
{
    static NSMutableDictionary *serialQueueDict = nil;
    if (serialQueueDict == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            serialQueueDict = [[NSMutableDictionary alloc] initWithCapacity:TokenTypeCount];
        });
    }

    dispatch_queue_t queue;

    @synchronized (self) {
        NSString *key = [TokenManager tokenName4Type:tokenType];
        key = [key stringByAppendingString:NSStringFromClass([self class])];
        NSValue *value = serialQueueDict[key];

        if (value == nil) {
            queue = dispatch_queue_create(key.UTF8String, DISPATCH_QUEUE_SERIAL);
            value = [NSValue valueWithBytes:&queue objCType:@encode(dispatch_queue_t)];
            serialQueueDict[key] = value;
        } else {
            [value getValue:&queue];
        }
    }

    return queue;
}

@synchronized (self) {行的正下方,它会调用Class方法:

+ (NSString *)tokenName4Type:(TokenType)tokenType
{
    NSString *string = nil;

    switch (tokenType) {
        case TokenTypeBiz:
            return @"TokenTypeBiz";
            break;

        case TokenTypeWeb:
        default:
            string = @"TokenTypeWeb";
            break;
    }

    return string;
}

代码就在那里,但有时(几次)应用程序会在unrecognized selector sent这一行崩溃,无论是调试还是发布。

任何提示将不胜感激。感谢。

0 个答案:

没有答案