Is there an INTERNET permission in iOS?
Asked Answered
T

1

6

i have a weird problem with dio package for flutter on iOS device. i wrote an app which sends a GET request to a url. everything works perfectly on Android but looks like the request doesn't go thru on iOS. nothing happens no error nothing at all. i had the same problem on android too but i found out that i forgot to add INTERNET permission into my manifest file. i'm guessing the same situation occurring in iOS.

is there any INTERNET permission in iOS that i need to add info.plist ?

void _checkVersionAndPreferences() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String prefsRes = prefs.getString('access_token') ?? '';
    String buildNumber = _packageInfo.buildNumber ?? '1';
    Dio dio = Dio();
    _cancelToken = CancelToken();
    Future.delayed(Duration(seconds: 10), () {
      if (_getRequestSuccess == false) {
        _cancelToken.cancel();
        _checkVersionAndPreferences();
        _showSnackBar(
            content: 'تلاش مجدد برای برقراری ارتباط',
            duration: Duration(seconds: 3),
            leading: Icon(Icons.refresh, color: Colors.black));
      }
    });
    Response response = await dio.get(
        'https://snapmelk.com/api/v1/panel/checkVersion/' + buildNumber,
        cancelToken: _cancelToken);
    try {
      Map respJson = jsonDecode(response.data);
      setState(() {
        _getRequestSuccess = true;
      });
      if (respJson['error']) {
        _showSnackBar(
            content:
                (respJson['errorMsg'] != null && respJson['errorMsg'] != '')
                    ? respJson['errorMsg']
                    : 'خطا در اتصال دریافت اطلاعات آخرین نسخه',
            leading: Icon(Icons.warning),
            backgroundColor: Colors.red,
            textColor: Colors.white);
      } else {
        if (respJson['NewUpdate']) {
          _checkDialogAnswer(respJson, prefsRes);
        } else {
          _checkPrefs(prefsRes);
        }
      }
    } catch (e) {
      _showSnackBar(
          content: 'خطا در اتصال با سرور. لطفا در زمانی دیگر مراجعه کنید',
          leading: Icon(Icons.warning),
          backgroundColor: Colors.red,
          textColor: Colors.white);
    }
  }
Theomorphic answered 25/4, 2020 at 17:57 Comment(6)
Are you reaching out over HTTPS or plain HTTP? iOS prevents HTTP connections by default, see Preventing Insecure Network ConnectionsOutgo
i'm using HTTPS.Theomorphic
developer.apple.com/documentation/bundleresources/…Dewain
You'll need to show your code. The most common cause of this is failure to call .resume() on a URLSessionTask, but mixing in dio and flutter, it's not obvious what you're actually calling. There is no special "internet" permission in iOS (and if there were, you'd get an error). We need to see the code.Shenika
There you go my friendTheomorphic
From that code, I'd begin digging into what "nothing happens" actually means. Add logging to see which lines run and which lines don't. Put a network sniffer on (or add logging at the server) to see if it actually sends the request or not. My suspicion, looking at the code, is that one of the methods doesn't do what you think it does (_checkDialogAnswer, _checkPrefs, or _showSnackBar), or that you're not actually calling this method at all (a very common mistake that leads to "nothing happens"). Add logging; see what does happen.Shenika
E
2

There's no network permission that you need to define for iOS in Flutter while using dio. To debug, I suggest logging the response from the executed requested with debugPrint(${response.data});, or if the request using dio itself could possibly throw an error, you might want to consider wrapping it inside the try-catch block as well.

Earleenearlene answered 6/9, 2022 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.