HomeiOS DevelopmentiOS state restoration with safe coding ... setting allowed courses

iOS state restoration with safe coding … setting allowed courses


I’ve not too long ago switched to utilizing state restoration (by implementing UIApplicationDelegate shouldSaveSecureApplicationState and shouldRestoreSecureApplicationState). The issue is that I get a variety of points with UIStateRestorationKeyedUnarchiver which does not acknowledge primary protected sorts like NSString and NSURL. Typically it is only a warning like:

*** -[UIStateRestorationKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving protected plist kind ''NSString' (0x1bf9cafa0) [/Library/Developer/CoreSimulator/Volumes/iOS_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework]' for key 'TextViewStringKey', although it was not explicitly included within the consumer allowed courses set: '{(
)}'. This can be disallowed sooner or later.

Typically I get a crash within the app:

*** Terminating app because of uncaught exception ‘NSInvalidUnarchiveOperationException’, cause: ‘worth for key
‘TodoTitleKey’ was of surprising class ‘NSURL’ (0x1bf9b8f28)
[/Library/Developer/CoreSimulator/Volumes/iOS_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS
17.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework].
Allowed courses are: {( )}’

So I find yourself having to make use of the decodeObjectOfClass every time I need to decode one thing, like:

NSString *calendarID = [coder decodeObjectOfClass:[NSString class] forKey: kStateRestorationCalendarID];

This will get tedious as a result of I’ve to make use of this in dozens of locations, with dozens of objects.

Is there a technique to set this globally with NSCoder, for functions of state restoration? I do know that if I used to be utilizing a separate NSSecureUnarchiveFromDataTransformer, it has a allowedTopLevelClasses class methodology, however I do not assume this works for state restoration archiver / unarchiver.

NSCoder appears to have a allowedClasses property, nevertheless it’s marked as read-only.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments