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

Swift - How to initialize object of class created with NSClassFromString
filename.h file not found error in XCode 8 while creating framework
Swift create local file, append other local file for use with NSURLSession.uploadTask
Use ImageMagick in Cocoa/OSX application
Xcode 8 storyboard error
Convert UIImage to Base64 in swift 2.3
uitableview reload not working on arm64 devices
When monitoringDidFailForRegion method is called?
ImageView of a custom CollectionViewCell is nil when it should be configured
Installing and using pod
How to pushing data to another page in creating pdf file
Use Custom Route with Google Maps or Apple Maps (iOS)
Fetch Realm objects that contain parameter
Will auto-updates still apply to extant app installs if I remove my app from the app store?
In 2017, how should we handle LAN requests without HTTPS in respect to ATS settings?
How to transfer large size video data from iPhone app to watch app

Categories

HOME
apache-spark
selenium
sqlite
actions-on-google
tags
backand
weight
streaming
windows-server-2012-r2
asp.net-mvc-3
h2o
wso2ei
openframeworks
axure
vscode-settings
countdown
swig
google-finance
jmeter-plugins
mlr
broker
polynomials
wso2cep
typemock-isolator
graphql-dotnet
whatsapi
mobile-center
toastr
vrtk
tensor
server-sent-events
gridstack
mask
jetty-9
drupal-webform
visualsvn-server
h5py
compass-lucene
tabview
virtualmin
gulp-babel
opal
http-status-code-500
adal.js
arm7
tpl-dataflow
fasta
maven-versions-plugin
autogen
liclipse
graph-traversal
replicate
turbo-c
hard-drive-failure
statistics-bootstrap
facebook-audience-network
pygments
pager
menustrip
ios-frameworks
accounts
okuma
highslide
xlform
illegalstateexception
subroutine
xelement
sqlj
xirr
wchar-t
session-replication
json4s
polygons
pegkit
bonfire
sslv3
mkpolyline
antiforgerytoken
imake
jasmin
gdk
syndication-feed
aps
tinkerpop-frames
dotliquid
dfsort
scala-pickling
parsekit
libtorrent-rasterbar
glulookat
firebird2.1
applaud
cocosbuilder
rpn
c++builder-xe2
nsinvocation
consistent-hashing
ruby-1.9.2
magento-1.5
android-assets
symstore
high-traffic
wmd
nhaml
templatebinding

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