将应用程序中的Cookie设置为iOS中的Safari [英] Set cookies from the app to Safari in iOS

查看:83
本文介绍了将应用程序中的Cookie设置为iOS中的Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要实现下一个功能:当用户登录应用程序时,它(该应用程序)需要将某些网站的Cookie(或任何其他数据)保存到移动Safari。目标是下次用户在Safari中打开该网站时不要使其登录。

In my app I need to implement next feature: when user logged-in in the app, it (the app) needs to save cookies (or any other data) for certain website to mobile Safari. The goal is to not make user log-in next time when he will open that website in Safari.

文档说,它不能在使用cookie的iOS上完成。有人知道其他解决方案吗?实现的必需功能是使其对用户安静,而无需打开Safari。

Documentation says that it can't be done on iOS using cookies. Does anybody know any other solution? Required feature of implementation is to make it 'silently' to user, without opening Safari.

更新

是否可以从移动Safari访问应用程序数据并获得一些回调?例如,当用户浏览网站时,网站将向应用程序发送一些回调,并获得有关用户数据的响应。

Is it possible to access app data from mobile Safari and get some callback? For example when user browses website the site sends some callback to the app and gets some response with user' data.

推荐答案

旧问题,但是您能否从应用程序中打开Safari到一个特殊的一次性URL,该URL将用户带到您托管的页面,传递从同一服务器上的API检索的令牌,然后验证该页面并设置Cookie?通过这种方式,可以在服务器上处理授权,服务器可以在响应中设置cookie。

Old question, but could you open Safari to a special one-time URL from your app which takes user to a page which you host, passing a token which you retrieve from API on same server, with page then validating token and setting cookie? That way authorization is handled on server, and server can set the cookie in the response.

您可以在应用中执行类似的操作

You could do something like this in your app

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://myhost.com/myhandler?token=PX2G16BWFKZBQWUKGF3BGRY2Z6BEJ7Z3PMO2GZ6S3R00JVWBVEO6VWBEXNK14IBJ5GKAY5EKBLAHNSAJ8"]];

然后位于myhost.com/myhandler的页面将读取和验证令牌,并在响应时设置cookie,以及然后使令牌无效。您还可以添加一个使用令牌的时间限制。

Then page at myhost.com/myhandler would read and validate token, and set cookie on response, and then invalidate the token. You could also add a time limit for how long the token could be used.

这篇关于将应用程序中的Cookie设置为iOS中的Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆