[
https://issues.apache.org/jira/browse/CB-2301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13826879#comment-13826879
]
Paul Kane commented on CB-2301:
-------------------------------
I was having lots of similar problems with my Cordova project. In XCode I was
regularly seeing crashes. But following Ross's suggestion I seem to have gotten
past them.
This is just an FYI post, not a thoroughly detailed recounting of what I did to
(seemingly) fix my problems, but I submit it in case it's helpful to anyone
else. I'm using Cordova 3.1.0 and my iPhone 5s is iOS 7.0.4.
To start, I created a sample project, added the socket.io client library, and
after deviceready I would connect to my server. If I ran my app, let it
connect, then suspended my app (hit the iPhone home button, say), I could see
the socket connection close on my server after about 30 seconds. If I then
locked my iPhone (manually), woke it back up, and then re-opened my app, I
could see in XCode that the socket.io "disconnect" event didn't fire until
after the phone was awakened. This seemed strange, but probably the best you
could do "out of the box" since socket.io has no knowledge of Cordova's "pause"
and "resume" events. Once awakened, socket.io would then reconnect
automatically to the server. However, about 3.5 minutes after I woke it up, the
app would crash. The ~3.5 minutes was strangely reliable (I could set a timer
and wait for it).
A weird (but possibly important side note) : I believe that this only happened
to me if I had a plugin loaded (any plugin). I have 6 plugins in my normal
project and any 1 of them seemed to trigger the crash. Without a plugin, the
app wouldn't seem to crash (could be wrong about this though).
Eventually what I did -- because obviously not using plugins wasn't an option
-- was to capture the Cordova "pause" and "resume" events and MANUALLY do a
socket.disconnect() and socket.socket.connect() (respectively). This was Ross's
suggestion. It's just a dash more work, but seems to have made all the
difference. Now the socket.io "disconnect" event happen in the background
before the app goes into completely suspension, and not after waking up. This
feels "cleaner" somehow, without JS and the real network state getting out of
sync. (I sure am glad that apps are allowed to run for a few seconds after
they've been suspended, exactly for this kind of situation.)
I also manually manage reconnections now too, rather than letting socket.io
handle them. This might not be critical, but it made it easier for me to keep
in my head the workflow of things. Now when I call socket.disconnect() it stays
disconnected, and doesn't try to immediately, automatically re-establish a
connection in the brief "background" state before the app is suspended.
P.S. : I think that changing "BackupWebStorage " to "none" might also have
helped (it seems like it was crashing faster and at a different point if that
was set to "cloud"). However this change on its own wasn't enough to solve the
problems completely.
> EXC_BAD_ACCESS on resume/wake on iOS device
> -------------------------------------------
>
> Key: CB-2301
> URL: https://issues.apache.org/jira/browse/CB-2301
> Project: Apache Cordova
> Issue Type: Bug
> Components: iOS
> Affects Versions: 2.2.0
> Environment: iPhone 5 running iOS 6.0.2 and Phonegap 2.2.0. (Xcode
> 4.5.2 on Mountain Lion)
> Reporter: Ross Holdway
> Assignee: Shazron Abdullah
> Priority: Critical
> Labels: cordova, ios, phonegap
> Fix For: 2.5.0
>
> Attachments: Sample.zip, Screenshot.png
>
>
> I have implemented a websocket connection (using socket.io) within my app
> which it uses to communicate with the server. On locking and waking the
> device, it disconnects and reconnects correctly, but on leaving the device
> locked for 1 minute or longer when unlocking, the application will crash
> sometimes instantly, or sometimes after reconnecting with the server.
> If I do the same, but run my app within mobile Safari, it does not crash,
> leading me to believe this is an issue with Phonegap/Cordova.
> On app crash, within Xcode I get within WebThread -
> WebCore::ThreadTImers::sharedTimerFiredInternal() an EXC_BAD_ACCESS (code=1)
> error
> Screenshot of crash state in Xcode
> -http://pictat.com/i/2013/1/28/24904screenshot.jpg
> Hopefully someone will have an idea as to what could be causing this, or
> recommend some tests for me to run etc because I'm really clueless on how to
> proceed with fixing this!
> Many Thanks,
> Ross
--
This message was sent by Atlassian JIRA
(v6.1#6144)