iOS 17 weird behaviour when using categories

Hello,

We have a legacy project that has a NSData category. This category is used to add a new method called "base64EncodedString" that we use for a custom base 64 encoding.

Up until iOS 17, everything worked and we had no issue with it. This how we use it:

    NSString* text = @"This is the string we want to encode";
    NSString* strArrRequests64 = [[text dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString];

We have a breakpoint in our implementation of base64EncodedString

- (NSString *)base64EncodedString
{
	size_t outputLength;
	char *outputBuffer = ....;
	
	NSString *result =
		[[[NSString alloc]
			initWithBytes:outputBuffer
			length:outputLength
		  encoding:NSUTF8StringEncoding]
		autorelease];
	free(outputBuffer);
	return result;
}

The strange thing is that we use this method for several calls in our app. In 80% of the cases it triggers the breakpoint and the encoding works as intended, but some calls do not and the encoding does not happen.

We have checked the class of [text dataUsingEncoding:NSUTF8StringEncoding] and for all calls is "NSMutableConcreteData".

This is a breaking change for iOS17 and it affects a lot of our clients. We have a solution for this particular case, but there are more categories inside our library which can be affected by this issue.

Please advise.

Replies

It's always risky to add a category to a framework class, especially when you add a method with a name that could easily be used internally within the framework. I don't know if that's what's happened in this case, but I'd suggest you change your method name to something of the form "MySpecialDisambiguator_base64EncodedString", or implement the method in a non-framework class instead (with the NSData object as a parameter) and see if that resolves the issue.

Thank you, @Polyphonic. That is a good suggestion and that was the solution for this particular case.

What intrigues me is that this code works on devices that have iOS < 17. It does not matter that it is built with the latest version of XCode or that we use the newest SDK. Something has changed on iOS 17.

We have several categories that are used in our legacy project and it would be hard to test all if all the features still work as intended.

What intrigues me is that this code works on devices that have iOS &lt; 17.

If you have conflicting categories, the exact behaviour you’ll see has always been undefined. The nature of undefined behaviour is that it can change based on hard-to-understand criteria, like the exact way that things are implemented within the OS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"