-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setcookie ios failed #118
Comments
by
|
Any update on this? I'm also getting this issue... |
setCookie still doesn't seem to work for iOS. It successfully saves it to the CookieManager but doesn't actually work on the WebView |
@nemoryoliver @daryll-fourie @Hiram-Y Try the latest version of the plugin. Also, this plugin changed its name to A full example that I tried on both Android (API level import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: InAppWebViewPage()
);
}
}
class InAppWebViewPage extends StatefulWidget {
@override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> {
InAppWebViewController webView;
final CookieManager cookieManager = CookieManager.instance();
@override
void initState() {
super.initState();
var expiresDate = DateTime.parse("2019-09-30 00:00:00.000").millisecondsSinceEpoch;
cookieManager.setCookie(url: "https://flutter.dev", name: "myToken", value: "wertygubnm5046rhndf", domain: ".flutter.dev", expiresDate: expiresDate);
cookieManager.setCookie(url: "https://flutter.dev", name: "myCookie", value: "myValue", domain: ".flutter.dev", expiresDate: expiresDate);
cookieManager.setCookie(url: "https://flutter.dev", name: "myCookie2", value: "myValue2");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("InAppWebView")
),
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://flutter.dev",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
)
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) async {
print(await controller.evaluateJavascript(source: "document.cookie"));
},
),
),
),
ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Icon(Icons.arrow_back),
onPressed: () {
if (webView != null) {
webView.goBack();
}
},
),
RaisedButton(
child: Icon(Icons.arrow_forward),
onPressed: () {
if (webView != null) {
webView.goForward();
}
},
),
RaisedButton(
child: Icon(Icons.refresh),
onPressed: () {
if (webView != null) {
webView.reload();
}
},
),
],
),
]))
);
}
} It prints all of my cookies:
|
It also successfully sets and gets it from CookieManager. but it weirdly doesn't get passed in the actual webview's cookie. I think I tried printing the actual document.cookie using evaluate javascript. I've also moved to that package already |
@nemoryoliver Can you share the code you tested and didn't work? Also, the device information and Xcode version, please? Thanks! |
url must be https |
@nemoryoliver excuse me, did you able to let CookieManager work with the webview with iOS. I'm currently having the same issue with iOS. It successfully saves it to the CookieManager but not able to see in Any help would be appreciated, |
sorry for the late response. what I did was used the https://pub.dev/packages/webview_flutter package plus the https://pub.dev/packages/webview_cookie_manager they work brilliant with cookies |
Hi, any news on this issue? |
@lugael please, provide the example code to test for iOS! This is my simple test code on iOS 16.0 and it works as expected: import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
final CookieManager cookieManager = CookieManager.instance();
var expiresDate = DateTime.parse("2023-09-30 00:00:00.000").millisecondsSinceEpoch;
await cookieManager.setCookie(url: Uri.parse("https://flutter.dev/"), name: "myToken", value: "wertygubnm5046rhndf", domain: ".flutter.dev", expiresDate: expiresDate);
await cookieManager.setCookie(url: Uri.parse("https://flutter.dev/"), name: "myCookie", value: "myValue", domain: ".flutter.dev", expiresDate: expiresDate);
await cookieManager.setCookie(url: Uri.parse("https://flutter.dev/"), name: "myCookie2", value: "myValue2");
runApp(MaterialApp(
home: new MyApp()
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
final GlobalKey webViewKey = GlobalKey();
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("CookieManager example")),
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
key: webViewKey,
initialUrlRequest: URLRequest(url: Uri.parse("https://flutter.dev/")),
onLoadStop: (controller, url) async {
print(await controller.evaluateJavascript(source: "document.cookie"));
},
onConsoleMessage: (controller, consoleMessage) {
print(consoleMessage);
},
),
),
]))
);
}
} It prints correctly my custom cookies:
|
@pichillilorenzo Here's an example of IOS, test on an iPhone 13 IOS 16
But on IOS only the website is left, the app doesn't set any cookies and doesn't show an error: |
@lugael you need to set the domain as |
It's work for me thanks |
I don't have to handle any subdomain in my case but anyway, specify
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue. |
The text was updated successfully, but these errors were encountered: