Skip to content

Instantly share code, notes, and snippets.

@piffie
Created December 13, 2013 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piffie/7944268 to your computer and use it in GitHub Desktop.
Save piffie/7944268 to your computer and use it in GitHub Desktop.
The Meteor LocalStorage implementation is not working on all iOS devices with private Browsing turned on. This is default in iOS 7. The reason is, that window.localStorage exists, but writing to window.localStorage.setItem throws an exception. This gist overrides the meteor implementation if this is the case.
@fix =
hasLocalStorage: ->
try
mod = new Date
localStorage.setItem mod, mod.toString()
result = localStorage.getItem(mod) == mod.toString()
localStorage.removeItem mod
return true
if $.browser.msie?
return true #meteor has special ie code.
return false
checkLocalStorageFix: ->
if @hasLocalStorage()
return
Meteor._localStorage = #override with local temporary store.
_data: {}
setItem: (key, val)-> @_data[key] = val
removeItem: (key) -> delete @_data[key]
getItem: (key)->
value = @_data[key]
return value if value?
null
Meteor.startup ->
fix.checkLocalStorageFix()
@crapthings
Copy link

it still takes time to login on ios 5.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment