Skip to content

iOS: NetInfo.isConnected returns always false #8615

Closed
@rkostrab

Description

@rkostrab

I am currently running RN 0.28.0...

NetInfo.isConnected.fetch().then(isConnected => {
      // variable isConnected is always false
    });

I would do a PR but I can't code for iOS.

Activity

hithacker

hithacker commented on Jul 7, 2016

@hithacker

I can also reproduce this with RN 0.29.0. I was running on 0.26.2 earlier and it worked fine with it. Going to try building from source and debug.

lixiaolihua

lixiaolihua commented on Jul 7, 2016

@lixiaolihua

+1

ryankask

ryankask commented on Jul 7, 2016

@ryankask
Contributor

I've reported the same issue before: #8469

Quick workaround is to add an event handler NetInfo.isConnected.addEventListener('change', Function.prototype)

thorbenandresen

thorbenandresen commented on Jul 9, 2016

@thorbenandresen

+1 and same issue with NetInfo.fetch().done() - always returns unknown

knowbody

knowbody commented on Jul 11, 2016

@knowbody
Contributor

I solved it this way:

componentDidMount() {
  const dispatchConnected = isConnected => this.props.dispatch(setIsConnected(isConnected));

  NetInfo.isConnected.fetch().then().done(() => {
    NetInfo.isConnected.addEventListener('change', dispatchConnected);
  });
}
Hamiltontx

Hamiltontx commented on Jul 16, 2016

@Hamiltontx

+1

lincwee

lincwee commented on Jul 18, 2016

@lincwee

we have found this bug in 0.29.2..

EastLee

EastLee commented on Jul 20, 2016

@EastLee

we have found this bug in 0.28

rkostrab

rkostrab commented on Jul 27, 2016

@rkostrab
Author

0.30.0 still not working

ryankask

ryankask commented on Jul 27, 2016

@ryankask
Contributor

The relevant code hasn't changed so it makes sense that it's still not working.

Note that I previously reported the bug here: #8469 where it details the cause and has sample code attached. Because of this, I think it makes sense to leave this closed.

The number of open RN issues grows daily so it's important to do our part and consolidate where possible.

AdityaAthavale

AdityaAthavale commented on Jul 29, 2016

@AdityaAthavale

I noted the same Issue today

uc-spr

uc-spr commented on Aug 1, 2016

@uc-spr

I am using 0.30.0 version , And i'm also found this error.

xing-zheng

xing-zheng commented on Aug 1, 2016

@xing-zheng
Contributor

the same issue to me, I am using RN@0.30.0 and the fetch always return unknown.

But we can use addEventListener instead.

NetInfo.addEventListener('change',
    (networkType)=> {
        this.setState({networkType})
    }
)

instead of:

NetInfo.fetch().done(
    (networkType)=> {
        this.setState({networkType})
    }
)

152 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help Wanted :octocat:Issues ideal for external contributors.Platform: iOSiOS applications.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @shergin@ryankask@brentvatne@hithacker@ivanzotov

      Issue actions

        iOS: NetInfo.isConnected returns always false · Issue #8615 · facebook/react-native