Bug in iPhone Simulator 5.1 with Xcode 4.5 using UIManagedDocument
Asked Answered
E

3

9

I have a very weird problem I've spent the last two days trying to solve... I had a piece of code that was working perfectly fine on Xcode 4.4 and iOS 5.1 Simulator, using the 5.1 SDK. After I updated to Xcode 4.5 and the 6.0 SDK, my code stopped working in the iOS 5.1 Simulator... even though it works perfectly fine in the iOS 6.0 Simulator. Was there any change I'm not aware of?

This is the code:

- (void)useDocument
{
    if (![[NSFileManager defaultManager] fileExistsAtPath:[self.database.fileURL path]]){
        [self.database saveToURL:self.database.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){
            [self setupFetchedResultsController];
    }];
    } else if (self.database.documentState == UIDocumentStateClosed){
        [self.database openWithCompletionHandler:^(BOOL success){
            [self setupFetchedResultsController];
        }];          
    } else if (self.database.documentState == UIDocumentStateNormal) {
        [self setupFetchedResultsController];
    }
}

For some reason saveToURL and openWithCompletionHandler never return in the 5.1 Simulator. Any one knows why?

Experiment answered 24/9, 2012 at 0:26 Comment(5)
I'm glad that I found your question, because I have exactly the same problem, and just found out that it seems to be a problem with the 5.1 Simulator. I guess your code is also based on the Stanford 2011 course (the methods 'useDocument' hints it).Desquamate
Yeah, my UIManagedDocument setup is a copy and paste from Paul's code. Only difference is a couple of lines to add support for lightweight migration.Experiment
I am having the same issue. Have you found any solutions to this issue? Thanks!Bettencourt
Not yet Yan, but as other people mentioned, if you run it on the device it will work fine. For some reason I still had problems if I ran from the device using Xcode, so I had to install the app (used TestFlight).Experiment
Have you guys installed Xcode 4.5.1? To me it looks like this bug still exists: simulator 5.0 and 6.0 work, but on simulator 5.1 the completion handler is still not called.Desquamate
J
5

I have the same problem under iPhone Simulator 5.1. The file is created after a long time (30 seconds). But the completion handler is never called. Did you try it on a device?

EDIT: This seems a bug in iOS Simulator 5.1. I compiled the code on my old iPad with iOS 5.1.1 and it worked without an error!

Japonica answered 25/9, 2012 at 5:58 Comment(1)
I did test once and it didn't work. But so many people are telling me it's simulator only that now I'm wondering if there wasn't another bug on my code when I tested.Experiment
D
5

Can't say for your project, but here it definitely was Xcode 4.5.

I have a copy of Xcode 4.3.1 with Simulator 5.1 on a virtual machine, and guess what: that one works flawlessly

-> Xcode4.3.1/Simulator5.1 works!

-> Xcode4.5 /Simulator5.1 is faulty

-> Xcode4.5.1/Simulator5.1 is faulty

As a workaround you can download version 5.0 of the simulator in Xcode -> Preferences -> Downloads. That one works.

Desquamate answered 25/9, 2012 at 14:27 Comment(1)
XCode 4.5.2 iOS 5.1 simulator doesn't work, iOS 5.0 simulator (and 6.0 simulator) does. Thanks.Wickham
F
-1

I don't believe that the problem is in the simulator. I had exactly the same problem (app runs on 6.0 but not in 5.x) and I also tried to run it in a device and it happens exactly the same. (I explained my problem here)

My problem happens both in 5.0 and 5.1. For instance, I can't even run a "Master-detail Application" template properly in any iOS 5.x simulator, but it works fine in 6.0. Even if I try this template in a device, it doesn't work properly. So I really believe that the problem is in XCode 4.5.

Fumble answered 10/10, 2012 at 8:53 Comment(2)
Please re-read the question and the answers:the problem described here is about the 5.1 simulator. Your problem is about iOS 5.x vs iOS 6.0.Desquamate
The original question states a similar problem to mine. The user can run it in 6.0 Simulator but not in 5.1 after XCode 4.5 update, the same as me.Fumble

© 2022 - 2024 — McMap. All rights reserved.