-[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class - ios

I have an error I don't understand after I updated my app. I have an app already in the app store. I have some app specific data archived and stored in a file inside application support directory. I was reading and storing the data every time when the app is launched and sent to background. Everything was fine so far. Now I released an update to the app. After the update when I launch the app and try to unarchive the data it crashes with below exception.
-[NSKeyedUnarchiver decodeObjectForKey:]:
cannot decode object of class (ProjectName.ProjectFile) for key (root);
the class may be defined in source code or a library that is not linked.
If I delete the app and install the app again everything works fine.
Both my original app and update are written in Swift. I haven't changed the file name also from version 1 to 2. Does any one know what is happening ?

I found the reason for the above.
Basically I changed the project target name from version 1 to version 2. So it was trying to decode ProjectName2.ProjectFile instead of ProjectName.ProjectFile.
The possible way to avoid is #objc(PFUserUtils) for the class when you start the first version. If you change the target name like me, use NSKeyedUnarchiver.setClass(className forClassName:name) method to set the class name to old one.

Related

'Attempt to mutate immutable object with deleteCharactersInRange': Xcode 7.2 error creating archive to upload to appstore

In Xcode 7.2 when creating an archive to upload to App Store (using Windows > Organizer)
I get the following error: 'Attempt to mutate immutable object with
deleteCharactersInRange'
The following log is generated for the error:
2016-01-13 11:11:24 +0000 The store submission configuration response
failed with errors: (
"Error Domain=WorkerErrorDomain Code=-10001 \"Attempt to mutate immutable object with deleteCharactersInRange:\"
UserInfo={MZUnderlyingException=Attempt to mutate immutable object
with deleteCharactersInRange:, NSLocalizedDescription=Attempt to
mutate immutable object with deleteCharactersInRange:,
NSLocalizedFailureReason=Attempt to mutate immutable object with
deleteCharactersInRange:}" ), warnings: ( ), info messages: ( ).
2016-01-13 11:11:26 +0000 [MT] Presenting: Error
Domain=WorkerErrorDomain Code=-10001 "Attempt to mutate immutable
object with deleteCharactersInRange:"
UserInfo={MZUnderlyingException=Attempt to mutate immutable object
with deleteCharactersInRange:, NSLocalizedDescription=Attempt to
mutate immutable object with deleteCharactersInRange:,
NSLocalizedFailureReason=Attempt to mutate immutable object with
deleteCharactersInRange:}
I am using Swift 2 in my project and have integrated Objective-C based PayU payment Gateway library.
Is there someway I can track the source of the error, to resolve the issue.
I am able run the app successfully in the simulator and a real iPhone device.
I just had the same problem in Xcode 7.2
At the end, I used the Application Loader instead, and I succeed to upload the app.
Hope that helps.
I know I am replying a ten months old post, but I still wish to post my answer in case somebody else ran into the same problem as me and desperately need an answer.
I have came across with the same error message too, and I found that I haven't add my app in iTunes connect.
In the end, I have my app added into iTunes connect and the error is gone.
You can also try submitting from Xcode again if you get this error. The second try worked for me - was able to submit with no issues.
Try doing the next:
Close xcode.
Try to clean derived data folder.
Open xcode then clean the project & archive using xcode.

Today Extension Crashes before launching on iOS 8.1.2

I've been making a today extension that downloads articles from a feed and display the latest ones.
The whole thing worked fine on iOS 8, still worked on iOS 8.1, then came iOS 8.1.2 and we started having complaints about the today extension not working anymore.
I tried debugging on iOS 8.1.2 devices, and before the extension even launch, it crashes with this error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: <__NSConcreteUUID 0x174027280> 5AFB07AB-5DCD-46FE-8D07-44DE0F3789F2)'
I have read this post about frequent bugs happening when developing a today extension : http://www.atomicbird.com/blog/ios-app-extension-tip
In his post, Tom Harrington says :
In iOS 8 (and other recent versions), enabling modules in Xcode's build settings means you don't need to explicitly list all the frameworks you want to use. They'll be found automatically.
But this isn't the case with NotificationCenter.framework, which Today extensions use. If you remove that from the build settings, you won't get any build warnings or errors. But when you try to load the extension, you'll get an exception from libextension.dylib and your extension won't load. The exception message is not enlightening:
2014-08-16 12:06:53.793 TodayTestExtension[41313:6111763] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason: '*
setObjectForKey: object cannot be nil (key: <__NSConcreteUUID
0x7fd729422390> ED3B42F8-66CD-4CB0-BCD5-F3DBA6F34DB5)'
If you're doing a today extension, just leave that framework in the build settings. It shouldn't need to be there, but it does.
My extension does include NotificationCenter.framework in its build settings, but I suspect my problem might be similar in some way.
Anyone faced a similar problem? Any idea how to solve it?
This error also occurs if you use NSExtensionPrincipalClass inside "Info.plist" in order to define a base class (instead of using a storyboard) with the name of a ViewController which does not exist.
When using Swift, make sure to prefix the class with the module name (usually the name of the target) like "Module.MyViewController".
Eventually I tried to remove NotificationCenter.framework from my target and put it back, cleaned the project, and it's now working again. I guess the framework wasn't properly linked after all, though I could see it on my target with xcode. Also, I can't figure out why it did work, then stopped working with the arrival of 8.1.2.
I fixed this issue by adding the #objc attribute to the Swift class.
#objc(NotificationViewController)
class NotificationViewController: UIViewController, UNNotificationContentExtension {
...
}
Just experienced the same issue. For me, it was "Main Interface" property in "General settings" of the Keyboard target. It was blank, and i set it to my storyboard file and now it works like a charm.

How to add momd(managed object model) into ios framework?

I am trying to convert my ios app(XYZ) into framework(XYZ.framework) so that it can be included in other ios applications. Went through below links and able to develop a framework.
LINK1:LINK1
LINK2:LINK2
But when i include my framework in other apps and try to compile for first time , xcode is throwing error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.". I followed below steps and get rid of this error.
STEP1: Added XYZ.framework in other app and compiled for first time, but xcode gave error mentioned above.
STEP2: Added XYZ.momd(by drag and drop) along with XYZ.framework in other application. Compiled it and Xcode didn't throw any error.
STEP3: Removed XYZ.momd from other application and compiled it. Xcode didn't throw any error!!!!
Should i give XYZ.momd along with XYZ.framework while distributing XYZ.framework, so that XYZ.momd can be included in other applications? I googled, but didn't get how to add momd inside framework and include it in other applications.

Could not instantiate class named ADBannerView after Removing iAD

Weird thing that I have spent about 4 hours debugging:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView'
I used to have iAD and then removed it. Now I use Google AdMob.
I have macros set up to determine the free/paid version. On the free version that is supposed to show ads, everything is fine and it displays the AdMob ads.
In the paid version, which does not call any ads, I get this error: Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView'
The only thing I can think of is that I may have an old iAd Banner View somewhere, but I can't find it!
Any hints?
Also: Everything works fine on the simulator.
Have you checked to make sure that there are no ADBannerViews in Interface Builder? The sort of error you are seeing says that the app is trying to create one somewhere.
Educated guess:
are you using the UI State Preservation & Restoration API? If so return NO from application:shouldSaveApplicationState: to get rid of the current saved state.
Once that works you should implement some kind of restoration version checking to prevent crashes on your users devices.
If that doesn't work, or you are not using state restoration, try to delete the app from the device. If you deploy from Xcode files are only added, never removed. So it's possible that an old file references ADBannerView. Delete the app to get rid of such orphan files.
Edit: That link should take you to the "Encode version information along with the rest of your app’s state." section. It doesn't, but you will find a small info about version checking at the bottom of the page.

iOS Persistent store issue

I am using core data with preloaded sqlite database. I am encountering a strange issue, the app works on the simulator, but when I try run it on a device, e.g. iPad, I get the error below.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject persistentStore]: unrecognized selector sent to instance 0x3bebf50'
I recreated the sqlite database from the model and repopulated the database, but I still get the same error. I've checked the 'Compiled Sources' and 'Copy Bundle Resources' in the build phase section and the files are all there.
Code:
http://pastebin.com/fTTgEA3W
Been racking my brain and can't seem to understand why it's not working, any help would really be appreciate.
Thank you for your time and if you need any more information please let me know.
First measure: delete the app and reinstall.
Second measure: text search for a call to persistentStore in your code. It is apparently going to an address that is a NSManagedObjectContext which does not have this method. Fix the error if you find it.
Third measure: review your recreation algorithms to make sure you are building the store correctly. In my projects with big stores, I usually have a SETUP flag that I switch on if the store needs to be imported from raw data, which normally works only in the simulator because of the memory needs. (When SETUP is off and there is no store, the one generated previously is copied over.) Maybe on the iPad you do not have enough memory to do the data import.

Resources