ios


Webpage cookies are not detected by UIWebView


I am developing iOS app that loads a webpage using UIWebView
The web page sets four cookies:
Two for Google Analytics, _ga and _gat
One for my web application unique vistors counter
One for my webpage to detect whether user has voted or not.
If this cookie available then display the poll results.
From Firefox's Storage Inspector I see all my cookies as expected, see screenshot:
However, from iOS I printed NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies from inside webViewDidFinishLoad and there is only two of four expected cookies, also iOS users can vote as many times as they wanted because cookies are not detected (or not stored in iOS device):
if let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies {
for c in cookies {
print("*******************")
print("name: \(c.name)")
print("domain: \(c.domain)")
print("value: \(c.value)")
print("path: \(c.path)")
print("expiresDate: \(c.expiresDate)")
}
}
Why my iOS app does not detect my custom cookies and only detects my Google Analytics ones?
NOTE 1: I have also added this code to my app:
func applicationDidBecomeActive(application: UIApplication) {
NSHTTPCookieStorage.sharedHTTPCookieStorage().cookieAcceptPolicy = NSHTTPCookieAcceptPolicy.Always
}
NOTE 2: My backend is SharePoint web application
A few ideas:
The device's Safari "Block Cookies" settings override any changes to the cookieAcceptPolicy. The default policy of this setting on the device is "Allow from Websites I Visit," which depending on your iOS device's version, allows third-party cookies. Testing with iOS 9.3.x shows that third party cookies are persisted in a UIWebView with the default settings, but do not persist with the settings "Allow from Current Website Only" or "Always Block."
Check if the device persists your cookie with the different Safari cookie settings.
Additionally, does your cookie have an expiration date set? I've found that cookies without an expiration date set are treated as session cookies in a UIWebView, which only persist with the lifecycle of the web view that received it.

Related Links

How to allow audio to continue to play when app is backgrounded?
How to limit the pulling distance with a refresh control?
Image fits into UICollectionView Cell
Caching the downloaded data
Core Location and Google Maps
(Objective C) NSDate is nil to convert a date in String
Swift need to reload TableView that is contained within a containerView
Remove iAds from SKScene
Adjust UICollectionView Size Dynamically to Ensure No Inter Item Spacing
How to replace Detail in UISplitViewController in Swift?
Adding Delay In A For Loop Without Blocking UI
Swift 1/2 UITextView suggestion by tag “#” or “#”
UICollectionViewController that looks like UITableViewController
iPhone simulator screenshot is not in proper dimension
How to update app via Xcode 5.1.1 for iOS 9
How to load txt file to UITextView with attributedString?

Categories

HOME
document
compiler-errors
watson
android-wear
tsql
splunk
push
research
telnet
nanotime
lighttpd
lag
factory-girl
records
helpers
eigen3
orientdb-2.1
silk-performer
gyroscope
code-analysis
centroid
sencha-touch-2
dsc
selenium-edgedriver
parallax
listbox
desktop-app-converter
rrd
ucwa
chai
blockui
p4-lang
vue2
amazon-elasticsearch
mamp-pro
php-5.5
project-centennial
permgen
mergesort
phasset
msysgit
sql-insert
mrtg
mashery
abbyy
masspay
redux-framework
clientid
linqtocsv
autopy
sample-data
phone-number
axlsx
android-listfragment
cbc-mode
stringr
xerces
generalization
declaration
min3d
words
puppet-enterprise
kue
nolio
mysql5
epoll
sendto
mui
cpp-netlib
nhunspell
twill
grunt-contrib-copy
jxta
dfsort
sshj
webcal
gdb-python
asp.net-authentication
src
northwind
doophp
guvnor
google-profiles-api
f2c
ramaze
mkmapviewdelegate
iequalitycomparer
project-settings
anemic-domain-model
contracts
sharepoint-feature
code-statistics

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App