0

I'm getting the following error when running my app:

+[NSData dataFromBase64String:]: unrecognized selector sent to class 0x1aff66598 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSData dataFromBase64String:]: unrecognized selector sent to class 0x1aff66598'

The caller looks like this:

NSString* decodedData = [self base64Decode:encodedData];

And the method definitions are as follows:

- (NSString *)base64Decode:(NSString *)base64String {
    NSData *plainTextData = [NSData dataFromBase64String:base64String];
    NSString *plainText = [[NSString alloc] initWithData:plainTextData encoding:NSUTF8StringEncoding];
    return plainText;
}

// This is in another class
+ (NSData *)dataFromBase64String:(NSString *)aString {
    NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
    if( data == nil )
        return nil;
    size_t outputLength;
    void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
    NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
    free(outputBuffer);
    return result;
}

I'm not sure what I'm doing wrong...

user1695758
  • 173
  • 1
  • 3
  • 14

1 Answers1

3

Is your implementation of 'dataFromBase64String:' in objective-C Category in a static framework or library?

If it is the case, methods in the category are not included at linking and so are not found at runtime unless you add flags '-ObjC -all_load' on OTHER_LINKER_FLAGS in Xcode.

see https://developer.apple.com/library/content/qa/qa1490/_index.html

Nicolas Buquet
  • 3,880
  • 28
  • 28
  • Thank you! What does `-all_load` do? It seems to work with only `-ObjC` and `-all_load` doesn't seem to affect it so I'm wondering – hyouuu Jun 16 '22 at 03:41
  • 1
    -ObjC or -all_load force to load all code defined in Objective-C category. It forced the linker to embed code denifed in Obj-C category. Else this code is skipped and won't be available at runtime. – Nicolas Buquet Jun 16 '22 at 13:41