Friday, February 23, 2024
HomeiOS DevelopmentiOS state restoration with safe coding ... setting allowed lessons

iOS state restoration with safe coding … setting allowed lessons


I’ve lately switched to utilizing state restoration (by implementing UIApplicationDelegate shouldSaveSecureApplicationState and shouldRestoreSecureApplicationState). The issue is that I get loads of points with UIStateRestorationKeyedUnarchiver which does not acknowledge fundamental secure varieties like NSString and NSURL. Generally it is only a warning like:

*** -[UIStateRestorationKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving secure plist sort ''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', regardless that it was not explicitly included within the consumer allowed lessons set: '{(
)}'. This might be disallowed sooner or later.

Generally I get a crash within the app:

*** Terminating app resulting from uncaught exception ‘NSInvalidUnarchiveOperationException’, purpose: ‘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 lessons 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 approach 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 technique, however I do not assume this works for state restoration archiver / unarchiver.

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



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments