Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable cookies for iOS 7 in PhoneGap Build

I'm trying to get my WebApp to work on my iPad (iOS 7). According to all the research I've done, it seems like you need to enable cookies specifically (goodness knows why!)

I found this post on SO:

How to enable cookies for Android phonegap 1.8.0 app?

Thats all good and well, apart from the fact I'm using PhoneGap Build to create my app (thus don't have access to those files to edit)

Can anyone suggest what I can do? It seems insane that I can't use localStorage (or cookies) on my iOS app without doing this hack! (my app works perfectly on Android, which doesn't have this issue).

I've looked at installing XCode and manually coding/compiling the app, but this will only work on a Mac (which I don't have)

UPDATE: Having a look around, it seems that the only solution (I can find), is to write a plugin to enable the cookies. Thats all good and well- but:

  • I don't have a Mac to write it on
  • I can program a lot of languages, but Java is not one of them
  • How would I even get it added to their build list, so I could include it!

Would anyone be interested in writing a plugin for me? As far as I can see it would just need to invoke:

CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webView = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);

This is driving me up the wall!

like image 790
Andrew Newby Avatar asked Nov 11 '22 18:11

Andrew Newby


1 Answers

Just going over my questions, and thought I'd answer this one - It seems that for some reason, iOS doesn't like loading the localStorage() on the page ready. To get around this, you have to also set a 1.5 second timer - so it doesn't run before iOS has loaded localStorage(). i.e:

setTimeout(function() { doInit() } , 1500);

This isn't ideal - and it would be much better if there were a way to enable cookies for iOS in PhoneGap Build, without having to be able to write a plugin to do it (which I don't have the skills to do ;))

like image 88
Andrew Newby Avatar answered Nov 15 '22 06:11

Andrew Newby