-
-
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
Adding a cookie not working on ios? #338
Comments
That's because you are However, I noticed that Here is an example using import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
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(
initialRoute: '/',
routes: {
'/': (context) => CookieManagerExample()
}
);
}
}
class CookieManagerExample extends StatefulWidget {
final CookieManagerExampleState state = CookieManagerExampleState();
@override
CookieManagerExampleState createState() => state;
}
class CookieManagerExampleState extends State<CookieManagerExample> {
InAppWebViewController webViewController;
final CookieManager _cookieManager = CookieManager.instance();
@override
void initState() {
super.initState();
final expiresDate =
DateTime.now().add(Duration(days: 3)).millisecondsSinceEpoch;
_cookieManager.deleteAllCookies().then((value) {
_cookieManager.setCookie(
url: "https://flutter.dev/",
name: "session",
value: "54th5hfdcfg34",
domain: ".flutter.dev",
expiresDate: expiresDate,
isSecure: true,
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://flutter.dev/",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true
)
),
onWebViewCreated: (InAppWebViewController controller) {
webViewController = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) async {
List<Cookie> cookies = await _cookieManager.getCookies(url: url);
cookies.forEach((cookie) {
print(cookie.name + " " + cookie.value);
});
},
),
),
),
])
)
);
}
} |
@pichillilorenzo Any idea when this release will be up? I'm unable to set a cookie either in Android or iOS. I'm using await in an async function to first delete all cookies and then set them. When I run 'getCookie' immediately after, the cookie doesn't exist... |
Here's an example of what I'm doing, with some data redacted. When I print the list of cookies like you did in your example above, I don't see the cookie I just set. In addition, 'cookieData' is null. |
@pichillilorenzo thanks a lot for your answer. |
@SwannLV I tested it on iOS simulator and it is working. @SwannLV and @jgadsby could you try in a fresh app the example code I gave to you? |
I found my problem: cookie.domain not starting with a dot does seem to work on ios. |
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. |
Environment
Flutter version: 1.17
Plugin version: 3.1.0
iOS version: 13.3
Device: Iphone11 simulator
Description
Adding a cookie is working for me on android but not on ios simulator.
Here is my code:
Have I missed some configuration?
Thanks a lot!
The text was updated successfully, but these errors were encountered: