QNetworkConfigurationManager onlineState && iOS 10.3.2 problems (OBJECTIVE_SOURCES)


  • Qt Champions 2016

    there are known problems to always get the correct online state from iOS
    my current workaround was this:
    see https://bugreports.qt.io/browse/QTBUG-49751?focusedCommentId=354170&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-354170
    see also https://bugreports.qt.io/browse/QTBUG-56151 and https://bugreports.qt.io/browse/QTBUG-58946

    my workaround was working up to iOS 10.2.x
    just updated

    • OSX from 10.11.6 to macOS 10.12.5
    • Xcode from 8.2 to 8.3.3
    • my iOS test devices from 10.2.1 to 10.3.2
    • all projects from Qt 5.8 to 5.9

    then I recognized that my workaround didn't work as before and always reports iOS device as online - even while airplane mode is set
    noticed that now there are 2 network adapters always active:

    • utun0 (as before)
    • en2 (new)

    en2 normaly means an ethernet adapter. curious that iOS 10.3.2 reports en2 as active on my iPhone 6 ;-)

    I changed my workaround and now if only utun0 and/or en2 are reported as active from QNCM I detect this as offline

    there should be a better and more robust way
    fortunately QTBUG-56151 contains a workaround you can download
    https://bugreports.qt.io/secure/attachment/59615/NetworkConfTestWA.tar.gz

    from this download I wanted to test the 2nd way using Reachability by adding some Objective sources.
    But I cannot make this run

    This is the very first time I'm trying to add OBJECTIVE_SOURCES and I never did any iOS native development.
    probably I did something wrong.
    Here are my steps to integrate this into my QTQuickControls2 APP:

    I copied the objective sources into ios/src

    changed .pro:

    ios {
        OBJECTIVE_SOURCES += ios/src/Reachability.mm \
        ios/src/ReachabilityListener.mm
    
        QMAKE_INFO_PLIST = ios/Info.plist
        ios_icon.files = $$files($$PWD/ios/Icon*.png)
        QMAKE_BUNDLE_DATA += ios_icon
        ios_artwork.files = $$files($$PWD/ios/iTunesArtwork*.png)
        QMAKE_BUNDLE_DATA += ios_artwork
        app_launch_screen.files = $$files($$PWD/ios/MyLaunchScreen.xib)
        QMAKE_BUNDLE_DATA += app_launch_screen
    
        QMAKE_IOS_DEPLOYMENT_TARGET = 8.2
    
        include(ios_signature.pri)
    
        QMAKE_IOS_TARGETED_DEVICE_FAMILY = 1,2
    }
    

    added include:

    #if defined (Q_OS_IOS)
    #include "ios/src/ReachabilityListener.h"
    #endif
    

    changed class definition:

    class DataServer : public QObject
    #if defined (Q_OS_IOS)
        , private utility::ReachabilityDelegate
    #endif
    

    added statusChanged method

    #if defined (Q_OS_IOS)
    void DataServer::statusChanged(utility::NetworkStatus newStatus)
    {
        if (newStatus == utility::NotReachable) {
            // offline
        } else {
            // online
        }
    }
    #endif
    

    but getting error from build:

    Undefined symbols for architecture arm64:
      "_SCNetworkReachabilityGetFlags", referenced from:
          -[Reachability connectionRequired] in Reachability.o
          -[Reachability currentReachabilityStatus] in Reachability.o
      "_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
          -[Reachability startNotifier] in Reachability.o
      "_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
          -[Reachability stopNotifier] in Reachability.o
      "_SCNetworkReachabilitySetCallback", referenced from:
          -[Reachability startNotifier] in Reachability.o
      "_SCNetworkReachabilityCreateWithAddress", referenced from:
          +[Reachability reachabilityWithAddress:] in Reachability.o
      "_SCNetworkReachabilityCreateWithName", referenced from:
          +[Reachability reachabilityWithHostName:] in Reachability.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1
    

    any idea what I did wrong ?


  • Lifetime Qt Champion

    Hi,

    From a quick search, you may need to add LIBS += -framework SystemConfiguration to your .pro file.

    Hope it helps


  • Qt Champions 2016

    @SGaist cool - now it compiles :)
    Where do I find out which framework is needed ?


  • Lifetime Qt Champion

    Great !

    Apple's developer site is working well for that.


  • Qt Champions 2016

    @SGaist
    found https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html
    and then in the description the framework was mentioned

    edit: this is helpful to understand iOS Reachability: https://symbiotics.co.za/checking-network-status-in-ios-apps/

    thx again. without your help I never would have found this ;-)


  • Lifetime Qt Champion

    Great !

    You're welcome !

    Happy coding :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.