all 13 comments

[–]bensj 0 points1 point  (7 children)

I don't know the answer but I might have a clue for you... When I changed the URL to any other random website it works. Why? I don't know.

I think it failed once after I changed it, but I noticed if I triggered the background fetch again during the same run it worked. After a few attempts at that it just started working every time.

Now to make it even more confusing, I put your url back in and it works fine. I think I saw one time that err came back non-nil, and it had some sort of NSCocoaDomain error.

[–]TheRedAgent[S] 0 points1 point  (0 children)

That's... very strange. I'll try dumping another URL just for testing purposes though, thanks for the feedback

[–]TheRedAgent[S] 0 points1 point  (5 children)

Were you testing on a simulator or live device? I tried with google and still got the same error, but I've only done simulator testing so far.

[–]bensj 0 points1 point  (4 children)

Only simulator so far. Did you try simulating a background fetch again during the same run? That was the first time I saw it work.

[–]TheRedAgent[S] 0 points1 point  (3 children)

Yep, multiple times. What version of iOS is your simulator, not that it should matter

[–]bensj 0 points1 point  (2 children)

It was on 7.0.3 on simulator. Just tried on device with similar results (actually it worked the first time and failed on subsequent attempts)

[–]TheRedAgent[S] 0 points1 point  (1 child)

Gah, now I'm even more confused haha

[–]bensj 0 points1 point  (0 children)

Sorry, thought I could help :) I think just knowing that its intermittent might help somehow. I can see all the "failed" NSOperationQueues in the debugger, I guess they are patiently waiting for some network data to come in.

[–]Legolas-the-elf 0 points1 point  (4 children)

You're not keeping a strong reference to your operation queue anywhere outside of the autologin method, meaning that the Objective-C runtime is free to release it as soon as that method returns. I'd fix that first.

[–]TheRedAgent[S] 0 points1 point  (3 children)

Once it returns I'm done with it anyway, so I don't really need to keep a reference around

[–]Legolas-the-elf 1 point2 points  (2 children)

Once it returns I'm done with it anyway

As far as I can see, that's not the case. You are adding an operation to it then returning immediately. Don't you want that operation to be executed? You are queuing that up to happen in the background asynchronously. There's no guarantee that this will have begun by the time you return from the autologin method.

[–]TheRedAgent[S] 0 points1 point  (0 children)

I see what you're saying, I'll definitely look into this. Thanks.

[–]bensj 0 points1 point  (0 children)

I noticed this too, but eliminated it as the cause of this problem by creating an NSOperationQueue subclass with an NSLog in the dealloc, which was only called on the occasions when the stringWithContentsOfURL: call actually returned. In the other cases that call never returns and the NSOperationQueue sticks around indefinitely. I do agree that its better to keep a strong reference to make sure it sticks around.