One of my tabs (in my Tab-Based application) works on iOS 9, but does not work on iOS 8. Specifically, when trying to load data from a plist, I get the error shown below.
I have a "Planner" tab which saves entries into a plist.
iOS 8 Error - reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'
Saving Code:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
plistPath = appDelegate.plistPathInDocument
plistPath2 = appDelegate.plist2PathInDocument
// Extract the content of the file as NSData
let data:NSData = NSFileManager.defaultManager().contentsAtPath(plistPath)!
let data2:NSData = NSFileManager.defaultManager().contentsAtPath(plistPath2)!
do{
if(numOfViewWillAppear == 0)
{
if let x = NSKeyedUnarchiver.unarchiveObjectWithData(data2)
{
self.sortedSections = NSKeyedUnarchiver.unarchiveObjectWithData(data2) as! [String]
self.sections = NSKeyedUnarchiver.unarchiveObjectWithData(data) as! Dictionary
}
numOfViewWillAppear++
}
}
And AppDelegate preparation code:
func preparePlist()
{
let rootPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true)[0]
let url = NSURL(string: rootPath)
plistPathInDocument = (url?.URLByAppendingPathComponent("planner.plist").path)!
if !NSFileManager.defaultManager().fileExistsAtPath(plistPathInDocument){
let plistPathInBundle = NSBundle.mainBundle().pathForResource("planner", ofType: "plist")!
do {
try NSFileManager.defaultManager().copyItemAtPath(plistPathInBundle, toPath: plistPathInDocument)
print("plist copied")
}
catch{
print("error copying plist!")
}
}
else{
print("plst exists \(plistPathInDocument)")
}
}
Code in which I save items to the plist:
self.sections[todoItem.dueDate] = [Assignment(name: todoItem.name, dueDate: todoItem.dueDate)]
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
plistPath = appDelegate.plistPathInDocument
do{
let sectionsData = NSKeyedArchiver.archivedDataWithRootObject(sections)
sectionsData.writeToFile(plistPath, atomically: true)
}
Download an older app version:Go to the Purchased screen. For iPhone the Purchase screen is in the Updates tab. Select the app you want to download. If a compatible version of the app is available for your version of iOS simply confirm that you want to download it.
Apple ended support for all 9-11-year old iOS devices nearly 5 years, ago, in 2016.
Swift is a robust and intuitive programming language created by Apple for building apps for iOS, Mac, Apple TV, and Apple Watch. It's designed to give developers more freedom than ever. Swift is easy to use and open source, so anyone with an idea can create something incredible.
You can now download iOS 9.3 on your iPhone, iPad or iPod Touch. The latest version of Apple's mobile operating system will run on any iDevice from 2011 or later.
I'm not sure it will help but it's worth a try:
self.sections = NSKeyedUnarchiver.unarchiveObjectWithData(data) as! Dictionary
In the "saving code" in the above mentioned line, try using NSDictionary
instead of Dictionary
when running on iOS8.
I think I read somewhere, they only introduced Dictionary
class quite recently.
I'm not certain of this and I'm kind of newbie when it comes to iOS but it's worth a try...it might work.
If it works, just put the Dictionary
line in a if #available(ios 9.0 *)
condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With