Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. UIApplication.shared.canOpenURL implements in Qt
Forum Updated to NodeBB v4.3 + New Features

UIApplication.shared.canOpenURL implements in Qt

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
26 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    You can achieve that using Objective-C++ and the same class.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • M Offline
      M Offline
      Max Base
      wrote on last edited by Max Base
      #3

      Hello Dear @SGaist, Thank you for your message,
      You are an active, I did read some good reply befor in this case from you in this froum...

      I know about canOpenURL method, But i don't know how to call and use it....

      How we can use it? Thank you so much

      Also:

      • https://forum.qt.io/topic/46793/solved-using-objective-c-class-in-qt-c
      • https://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

      Can you show me one example in this case? It's not clear for me.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #4

        In your case, it's not as complicated as the link you found.

        Change the file extension of your cpp class implementation to .mm and in the function you want to make the check call, something like:

        NSURL *url = myUrl.toNSUrl();
         bool canOpen = [[NSApplication shared] canOpenUrl: url];
        

        [edit: fixed class name typo]

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 2 Replies Last reply
        2
        • M Offline
          M Offline
          Max Base
          wrote on last edited by Max Base
          #5

          @SGaist said in UIApplication.shared.canOpenURL implements in Qt:

          NSUrl

          Thank you, It was a good progress for first step.
          But we have error and cannot compile it.

          Error:
          photo_2020-01-17_02-06-19.jpg

          Code of .pro file:

          QT += widgets quick webview
          
          CONFIG += c++17
          
          
          DEFINES += QT_DEPRECATED_WARNINGS
          
          
          LIBS += -framework Foundation
          
          
          SOURCES += \
                  HandleURL.mm \
                  main.cpp \
          
          
          RESOURCES += qml.qrc
          
          
          QML_IMPORT_PATH =
          
          QML_DESIGNER_IMPORT_PATH =
          
          # Default rules for deployment.
          qnx: target.path = /tmp/$${TARGET}/bin
          else: unix:!android: target.path = /opt/$${TARGET}/bin
          !isEmpty(target.path): INSTALLS += target
          
          
          
          contains(ANDROID_TARGET_ARCH,arm64-v8a) {
              ANDROID_ARM64 = 1
              ANDROID_EXTRA_LIBS = \
                  $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libcrypto.so \
                  $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libssl.so
          
                      ANDROID_PACKAGE_SOURCE_DIR = \
                          $$PWD/android
          }
          
          contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
              ANDROID_EXTRA_LIBS = \
                  $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libcrypto.so \
                  $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libssl.so
          
              ANDROID_PACKAGE_SOURCE_DIR = \
                  $$PWD/android
          }
          
          
          
          
          DISTFILES += \
              android/AndroidManifest.xml \
              android/build.gradle \
              android/gradle/wrapper/gradle-wrapper.jar \
              android/gradle/wrapper/gradle-wrapper.properties \
              android/gradlew \
              android/gradlew.bat \
              android/res/values/libs.xml
          
          defineReplace(droidVersionCode) {
              segments = $$split(1, ".")
              for(segment, segments): vCode = "$$first(vCode)$$format_number($$segment, width=3 zeropad)"
              ## arm64-v8a, armeabi-v7a
              contains(ANDROID_TARGET_ARCH, arm64-v8a): \
                  suffix = 1
              else:contains(ANDROID_TARGET_ARCH, armeabi-v7a): \
                  suffix = 0
              return($$first(vCode)$$first(suffix))
          }
          
          
          
          
          ios {
             QMAKE_INFO_PLIST = ios/info.plist
          }
          
          VERSION = 1.2.3
          ANDROID_VERSION_NAME = $$VERSION
          ANDROID_VERSION_CODE = $$droidVersionCode($$ANDROID_VERSION_NAME)
          
          
          HEADERS += \
              HandleURL.hpp
          

          HandleURL.mm file:

          #include <QDebug>
          #include <QUrlQuery>
          #include <QUrl>
          #include <QDesktopServices>
          #include "HandleURL.hpp"
          #import <Foundation/NSUserNotification.h>
          #import <AppKit/NSApplication.h>
          #import <Foundation/Foundation.h>
          
          
          void HandleURL::handleURL(const QUrl &url) {
            // parse it...
            // protclname://methodName?token=dfgdfgdfgdfg&callbackurl=https%3A%2F%2Fgoogle.test.com
            QUrlQuery query(url);
            // qDebug() << url.toString();
            // qDebug() << query.queryItemValue("callbackurl");
            // qDebug() << QUrl::toString(...);
            //  NSUrl *urls = url.toNSUrl();
          
             //NSUrl *urls = url.toString().toNSUrl();
          
          NSUrl *urls = url.toNSUrl();
              bool canOpen = [[NSApplication shared] canOpenUrl: urls];
            qDebug() << canOpen;
              if(canOpen) {
                  QDesktopServices::openUrl(url);
              }
            emit incomingURL(query.queryItemValue("callbackurl"));
            // emit incomingURL(url.toString());
          }
          

          What's this problem?unknown type name nsurl

          Error: unknown type name NsURL

          JonBJ 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            It's NSURL

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply
            2
            • M Max Base

              @SGaist said in UIApplication.shared.canOpenURL implements in Qt:

              NSUrl

              Thank you, It was a good progress for first step.
              But we have error and cannot compile it.

              Error:
              photo_2020-01-17_02-06-19.jpg

              Code of .pro file:

              QT += widgets quick webview
              
              CONFIG += c++17
              
              
              DEFINES += QT_DEPRECATED_WARNINGS
              
              
              LIBS += -framework Foundation
              
              
              SOURCES += \
                      HandleURL.mm \
                      main.cpp \
              
              
              RESOURCES += qml.qrc
              
              
              QML_IMPORT_PATH =
              
              QML_DESIGNER_IMPORT_PATH =
              
              # Default rules for deployment.
              qnx: target.path = /tmp/$${TARGET}/bin
              else: unix:!android: target.path = /opt/$${TARGET}/bin
              !isEmpty(target.path): INSTALLS += target
              
              
              
              contains(ANDROID_TARGET_ARCH,arm64-v8a) {
                  ANDROID_ARM64 = 1
                  ANDROID_EXTRA_LIBS = \
                      $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libcrypto.so \
                      $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libssl.so
              
                          ANDROID_PACKAGE_SOURCE_DIR = \
                              $$PWD/android
              }
              
              contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
                  ANDROID_EXTRA_LIBS = \
                      $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libcrypto.so \
                      $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libssl.so
              
                  ANDROID_PACKAGE_SOURCE_DIR = \
                      $$PWD/android
              }
              
              
              
              
              DISTFILES += \
                  android/AndroidManifest.xml \
                  android/build.gradle \
                  android/gradle/wrapper/gradle-wrapper.jar \
                  android/gradle/wrapper/gradle-wrapper.properties \
                  android/gradlew \
                  android/gradlew.bat \
                  android/res/values/libs.xml
              
              defineReplace(droidVersionCode) {
                  segments = $$split(1, ".")
                  for(segment, segments): vCode = "$$first(vCode)$$format_number($$segment, width=3 zeropad)"
                  ## arm64-v8a, armeabi-v7a
                  contains(ANDROID_TARGET_ARCH, arm64-v8a): \
                      suffix = 1
                  else:contains(ANDROID_TARGET_ARCH, armeabi-v7a): \
                      suffix = 0
                  return($$first(vCode)$$first(suffix))
              }
              
              
              
              
              ios {
                 QMAKE_INFO_PLIST = ios/info.plist
              }
              
              VERSION = 1.2.3
              ANDROID_VERSION_NAME = $$VERSION
              ANDROID_VERSION_CODE = $$droidVersionCode($$ANDROID_VERSION_NAME)
              
              
              HEADERS += \
                  HandleURL.hpp
              

              HandleURL.mm file:

              #include <QDebug>
              #include <QUrlQuery>
              #include <QUrl>
              #include <QDesktopServices>
              #include "HandleURL.hpp"
              #import <Foundation/NSUserNotification.h>
              #import <AppKit/NSApplication.h>
              #import <Foundation/Foundation.h>
              
              
              void HandleURL::handleURL(const QUrl &url) {
                // parse it...
                // protclname://methodName?token=dfgdfgdfgdfg&callbackurl=https%3A%2F%2Fgoogle.test.com
                QUrlQuery query(url);
                // qDebug() << url.toString();
                // qDebug() << query.queryItemValue("callbackurl");
                // qDebug() << QUrl::toString(...);
                //  NSUrl *urls = url.toNSUrl();
              
                 //NSUrl *urls = url.toString().toNSUrl();
              
              NSUrl *urls = url.toNSUrl();
                  bool canOpen = [[NSApplication shared] canOpenUrl: urls];
                qDebug() << canOpen;
                  if(canOpen) {
                      QDesktopServices::openUrl(url);
                  }
                emit incomingURL(query.queryItemValue("callbackurl"));
                // emit incomingURL(url.toString());
              }
              

              What's this problem?unknown type name nsurl

              Error: unknown type name NsURL

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #7

              @Max-Base
              Start by reading https://doc.qt.io/qt-5/qurl.html#toNSURL, where you will see it's spelt NSURL.

              1 Reply Last reply
              1
              • SGaistS SGaist

                It's NSURL

                M Offline
                M Offline
                Max Base
                wrote on last edited by Max Base
                #8

                Hello,

                Thank you for your help and message.
                Sorry for my question @SGaist @JonB

                main.cpp file:

                #include <QApplication>
                #include <QQmlApplicationEngine>
                #include <QtWebView>
                #include <QDesktopServices>
                #include <QUrl>
                #include <QQmlContext>
                #include "HandleURL.hpp"
                
                int main(int argc, char *argv[])  {
                  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                  QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
                  QApplication app(argc, argv);
                  QtWebView::initialize();
                  QQmlApplicationEngine engine;
                  const QUrl url(QStringLiteral("qrc:/main.qml"));
                  QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
                    if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
                  }, Qt::QueuedConnection);
                
                  HandleURL *URLHandler = new HandleURL();
                  QDesktopServices::setUrlHandler("swish", URLHandler, "handleURL");
                
                  engine.load(url);
                  engine.rootContext()->setContextProperty("URLHandler", URLHandler);
                  return app.exec();
                }
                

                HandleURL.mm file:

                #include <QDebug>
                #include <QUrlQuery>
                #include <QUrl>
                #include <QDesktopServices>
                #include "HandleURL.hpp"
                
                #import <AppKit/NSApplication.h>
                #import <Foundation/Foundation.h>
                
                void HandleURL::handleURL(const QUrl &url) {
                    QUrlQuery query(url);
                    QUrl path(query.queryItemValue("callbackurl"));
                    NSURL *urls = path.toNSURL();
                    bool canOpen = [[NSApplication shared] canOpenUrl: urls];
                    qDebug() << canOpen;
                    if(canOpen) {
                        QDesktopServices::openUrl(url);
                    }
                    emit incomingURL(query.queryItemValue("callbackurl"));
                    // emit incomingURL(url.toString());
                }
                

                .pro file:

                QT += widgets quick webview
                CONFIG += c++17
                TEMPLATE = app
                DEFINES += QT_DEPRECATED_WARNINGS
                LIBS += -framework AppKit -framework Foundation
                
                SOURCES += \
                        HandleURL.mm \
                        main.cpp \
                RESOURCES += qml.qrc
                QML_IMPORT_PATH =
                QML_DESIGNER_IMPORT_PATH =
                # Default rules for deployment.
                qnx: target.path = /tmp/$${TARGET}/bin
                else: unix:!android: target.path = /opt/$${TARGET}/bin
                !isEmpty(target.path): INSTALLS += target
                contains(ANDROID_TARGET_ARCH,arm64-v8a) {
                    ANDROID_ARM64 = 1
                    ANDROID_EXTRA_LIBS = \
                        $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libcrypto.so \
                        $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libssl.so
                
                            ANDROID_PACKAGE_SOURCE_DIR = \
                                $$PWD/android
                }
                
                contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
                    ANDROID_EXTRA_LIBS = \
                        $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libcrypto.so \
                        $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libssl.so
                
                    ANDROID_PACKAGE_SOURCE_DIR = \
                        $$PWD/android
                }
                
                
                
                
                DISTFILES += \
                    android/AndroidManifest.xml \
                    android/build.gradle \
                    android/gradle/wrapper/gradle-wrapper.jar \
                    android/gradle/wrapper/gradle-wrapper.properties \
                    android/gradlew \
                    android/gradlew.bat \
                    android/res/values/libs.xml
                
                defineReplace(droidVersionCode) {
                    segments = $$split(1, ".")
                    for(segment, segments): vCode = "$$first(vCode)$$format_number($$segment, width=3 zeropad)"
                    ## arm64-v8a, armeabi-v7a
                    contains(ANDROID_TARGET_ARCH, arm64-v8a): \
                        suffix = 1
                    else:contains(ANDROID_TARGET_ARCH, armeabi-v7a): \
                        suffix = 0
                    return($$first(vCode)$$first(suffix))
                }
                ios {
                   QMAKE_INFO_PLIST = ios/info.plist
                }
                VERSION = 1.2.3
                ANDROID_VERSION_NAME = $$VERSION
                ANDROID_VERSION_CODE = $$droidVersionCode($$ANDROID_VERSION_NAME)
                HEADERS += \
                    HandleURL.hpp
                
                OBJECTIVE_SOURCES = HandleURL.mm
                

                HandleURL.hpp file:

                #ifndef HANDLEURL
                #define HANDLEURL
                
                  #include <QObject>
                  #include <QDesktopServices>
                
                  class HandleURL : public QObject {
                    Q_OBJECT
                    signals:
                      void incomingURL(QString path);
                    
                    public slots:
                      void handleURL(const QUrl &url);
                  };
                
                #endif
                

                Compile Error

                /Users/user/Desktop/silvcopy2/HandleURL.mm:7: error: 'AppKit/NSApplication.h' file not found
                #import <AppKit/NSApplication.h>
                        ^~~~~~~~~~~~~~~~~~~~~~~~
                
                :-1: error: Xcodebuild failed.
                

                photo_2020-01-18_01-06-48.jpg

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Did you re-run qmake after modifying your .pro file ?

                  If not then either nuke the build folder and restart a build or force a run of qmake.

                  On a side note, your .pro file has two issues: you have HandleURL.mm in both SOURCES and OBJECTIVE_SOURCES. If you are using a recent version of Qt, you don't need the later.

                  The other issue is the backslash after main.cpp.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Did you re-run qmake after modifying your .pro file ?

                    If not then either nuke the build folder and restart a build or force a run of qmake.

                    On a side note, your .pro file has two issues: you have HandleURL.mm in both SOURCES and OBJECTIVE_SOURCES. If you are using a recent version of Qt, you don't need the later.

                    The other issue is the backslash after main.cpp.

                    M Offline
                    M Offline
                    Max Base
                    wrote on last edited by Max Base
                    #10

                    @SGaist Thank you for your message.

                    But we have error yet!

                    .mm file:

                    #include <QDebug>
                    #include <QUrlQuery>
                    #include <QUrl>
                    #include <QDesktopServices>
                    #include "HandleURL.hpp"
                    #import <Foundation/NSUserNotification.h>
                    #import <AppKit/NSApplication.h>
                    
                    
                    void HandleURL::handleURL(const QUrl &url) {
                      // parse it...
                      QUrlQuery query(url);
                      // qDebug() << url.toString();
                      // qDebug() << query.queryItemValue("callbackurl");
                      // qDebug() << QUrl::toString(...);
                      //  NSUrl *urls = url.toNSUrl();
                    
                       //NSUrl *urls = url.toString().toNSUrl();
                    
                    NSUrl *urls = url.toNSUrl();
                        bool canOpen = [[NSApplication shared] canOpenUrl: urls];
                      qDebug() << canOpen;
                        if(canOpen) {
                            QDesktopServices::openUrl(url);
                        }
                      emit incomingURL(query.queryItemValue("callbackurl"));
                      // emit incomingURL(url.toString());
                    }
                    

                    .pro file:

                    #include Foundation/NSUserNotification.h>
                    #include AppKit/NSApplication.h>
                    
                    QT += widgets quick webview
                    CONFIG += c++17
                    TEMPLATE = app
                    DEFINES += QT_DEPRECATED_WARNINGS
                    LIBS += -framework AppKit -framework Foundation
                    
                    SOURCES += \
                            main.cpp
                    
                    RESOURCES += qml.qrc
                    QML_IMPORT_PATH =
                    QML_DESIGNER_IMPORT_PATH =
                    # Default rules for deployment.
                    qnx: target.path = /tmp/$${TARGET}/bin
                    else: unix:!android: target.path = /opt/$${TARGET}/bin
                    !isEmpty(target.path): INSTALLS += target
                    contains(ANDROID_TARGET_ARCH,arm64-v8a) {
                        ANDROID_ARM64 = 1
                        ANDROID_EXTRA_LIBS = \
                            $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libcrypto.so \
                            $$PWD/openssl-1.1.1a-clang/arm64-v8a/lib/libssl.so
                    
                                ANDROID_PACKAGE_SOURCE_DIR = \
                                    $$PWD/android
                    }
                    
                    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
                        ANDROID_EXTRA_LIBS = \
                            $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libcrypto.so \
                            $$PWD/openssl-1.1.1a-clang/armeabi-v7a/lib/libssl.so
                    
                        ANDROID_PACKAGE_SOURCE_DIR = \
                            $$PWD/android
                    }
                    
                    
                    DISTFILES += \
                        android/AndroidManifest.xml \
                        android/build.gradle \
                        android/gradle/wrapper/gradle-wrapper.jar \
                        android/gradle/wrapper/gradle-wrapper.properties \
                        android/gradlew \
                        android/gradlew.bat \
                        android/res/values/libs.xml
                    
                    defineReplace(droidVersionCode) {
                        segments = $$split(1, ".")
                        for(segment, segments): vCode = "$$first(vCode)$$format_number($$segment, width=3 zeropad)"
                        ## arm64-v8a, armeabi-v7a
                        contains(ANDROID_TARGET_ARCH, arm64-v8a): \
                            suffix = 1
                        else:contains(ANDROID_TARGET_ARCH, armeabi-v7a): \
                            suffix = 0
                        return($$first(vCode)$$first(suffix))
                    }
                    ios {
                       QMAKE_INFO_PLIST = ios/info.plist
                    }
                    VERSION = 1.2.3
                    ANDROID_VERSION_NAME = $$VERSION
                    ANDROID_VERSION_CODE = $$droidVersionCode($$ANDROID_VERSION_NAME)
                    HEADERS += \
                        HandleURL.hpp
                    
                    OBJECTIVE_SOURCES = HandleURL.mm
                    

                    ios -> info.plist file:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
                    <plist version="1.0">
                    <dict>
                      <key>CFBundleDisplayName</key>
                      <string>${PRODUCT_NAME}</string>
                      <key>CFBundleExecutable</key>
                      <string>${EXECUTABLE_NAME}</string>
                      <key>CFBundleGetInfoString</key>
                      <string>Created by Qt/QMake</string>
                      <key>CFBundleIdentifier</key>
                      <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
                      <key>CFBundleName</key>
                      <string>${PRODUCT_NAME}</string>
                      <key>CFBundlePackageType</key>
                      <string>APPL</string>
                      <key>CFBundleShortVersionString</key>
                      <string>${QMAKE_SHORT_VERSION}</string>
                      <key>CFBundleSignature</key>
                      <string>${QMAKE_PKGINFO_TYPEINFO}</string>
                      <key>CFBundleVersion</key>
                      <string>${QMAKE_FULL_VERSION}</string>
                      <key>LSRequiresIPhoneOS</key>
                      <true/>
                      <key>MinimumOSVersion</key>
                      <string>${IPHONEOS_DEPLOYMENT_TARGET}</string>
                      <key>NOTE</key>
                      <string>This file was generated by Qt/QMake.</string>
                      <key>UILaunchStoryboardName</key>
                      <string>LaunchScreen</string>
                      <key>UISupportedInterfaceOrientations</key>
                      <array>
                        <string>UIInterfaceOrientationPortrait</string>
                        <string>UIInterfaceOrientationPortraitUpsideDown</string>
                        <string>UIInterfaceOrientationLandscapeLeft</string>
                        <string>UIInterfaceOrientationLandscapeRight</string>
                      </array>
                    
                    
                    
                    
                    
                    
                    <key>CFBundleURLTypes</key>
                    <array>
                        <dict>
                            <key>CFBundleURLSchemes</key>
                            <array>
                                <string>swish</string>
                            </array>
                        </dict>
                    </array>
                    
                    
                    
                    
                    </dict>
                    </plist>
                    

                    photo_2020-01-18_23-37-09.jpg

                    Errors

                    /Users/user/Desktop/silvcopy22/HandleURL.mm:6: error: 'Foundation/NSUserNotification.h' file not found
                    #include <Foundation/NSUserNotification.h>
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    
                    /Users/user/Desktop/silvcopy22/HandleURL.mm:6: did not find header 'NSUserNotification.h' in framework 'Foundation' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks')
                    
                    :-1: error: Xcodebuild failed.
                    

                    Qt version: 5.13.2

                    Can you help and guide me?
                    Thank you

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Are you building for macOS or iOS ?

                      I built successfully for macOS but you seem to target the simulator.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        Max Base
                        wrote on last edited by
                        #12

                        We want this for iOS (iphone). @SGaist

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          From the documentation, NSUserNotification is a macOS API that is not deprecated.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • SGaistS SGaist

                            In your case, it's not as complicated as the link you found.

                            Change the file extension of your cpp class implementation to .mm and in the function you want to make the check call, something like:

                            NSURL *url = myUrl.toNSUrl();
                             bool canOpen = [[NSApplication shared] canOpenUrl: url];
                            

                            [edit: fixed class name typo]

                            M Offline
                            M Offline
                            Max Base
                            wrote on last edited by Max Base
                            #14
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Max Base
                              wrote on last edited by Max Base
                              #15

                              How we can access to UIApplication? and how can call canopenurl?

                              Target is iOS using Qt.

                              https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                It's written on the page you are linking as well as the URL: use the UIKit framework.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                M 1 Reply Last reply
                                1
                                • SGaistS SGaist

                                  It's written on the page you are linking as well as the URL: use the UIKit framework.

                                  M Offline
                                  M Offline
                                  Max Base
                                  wrote on last edited by
                                  #17

                                  @SGaist said in UIApplication.shared.canOpenURL implements in Qt:

                                  UIKit

                                  I don't know how to use UIKit, UIApplication in my Qt project.
                                  I cannot find any solution and sample code for this.
                                  Can you help me?

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    The exact same as you did with NSApplication, just use UIApplication in place.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • SGaistS SGaist

                                      In your case, it's not as complicated as the link you found.

                                      Change the file extension of your cpp class implementation to .mm and in the function you want to make the check call, something like:

                                      NSURL *url = myUrl.toNSUrl();
                                       bool canOpen = [[NSApplication shared] canOpenUrl: url];
                                      

                                      [edit: fixed class name typo]

                                      M Offline
                                      M Offline
                                      Max Base
                                      wrote on last edited by Max Base
                                      #19

                                      @SGaist said in UIApplication.shared.canOpenURL implements in Qt:

                                      NSURL *url = myUrl.toNSUrl();
                                      bool canOpen = [[UIApplication shared] canOpenUrl: url];

                                      Thank you so much for your message.

                                      Also how we can access to shared object when we are in another file?

                                      It's a globally object in OBJECT C (.mm) files?

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        The same way you did there. The function returns the singleton app instance.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        M 1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          The same way you did there. The function returns the singleton app instance.

                                          M Offline
                                          M Offline
                                          Max Base
                                          wrote on last edited by Max Base
                                          #21

                                          @SGaist said in UIApplication.shared.canOpenURL implements in Qt:

                                          The same way you did there. The function returns the singleton app instance.

                                          ![photo_2020-01-21_01-25-10.jpg]1579561486.png

                                          main.mm file:

                                          #include <QApplication>
                                          #include <QQmlApplicationEngine>
                                          #include <QtWebView>
                                          #include <QDesktopServices>
                                          #include <QUrl>
                                          #include <QQmlContext>
                                          #include "HandleURL.hpp"
                                          
                                          #include <QDebug>
                                          #include <QUrlQuery>
                                          
                                          //Two of these??
                                          #include <QUrl>
                                          #include <QDesktopServices>
                                          #include "HandleURL.hpp"
                                          //#import <AppKit/NSApplication.h>
                                          #import <UIKit/UIKit.h>
                                          #import <Foundation/Foundation.h>
                                          #include <QUrl>
                                          
                                          int main(int argc, char *argv[])  {
                                          	QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                                          	QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
                                          	QApplication app(argc, argv);
                                          
                                          	QUrl testURL("swish://paymentrequest?token=Shk9Q9C-RaatwCxZ_lYZ-u11ShJafIg5&callbackurl=https%3A%2F%2Fpay.direct2internet.com%2Fpay%2Fsuccess%3Fd2iwebpay-hh%3DV3n%252FCX%26d2iwebpay-tm%3D1579033717%26d2iwebpay%3D88c96710-5e08-43f6-bf46-f0ba89a3b3f6");
                                          	NSURL *urls = testURL.toNSURL();
                                          	bool canOpen = [[UIApplication sharedApplication] canOpenUrl: urls];
                                          
                                          
                                          	qDebug() << canOpen;
                                          	if(canOpen) {
                                          		QDesktopServices::openUrl(testURL);
                                          	}
                                          
                                          	QtWebView::initialize();
                                          	QQmlApplicationEngine engine;
                                          	const QUrl url(QStringLiteral("qrc:/main.qml"));
                                          	QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                                          				 &app, [url](QObject *obj, const QUrl &objUrl) {
                                          		if (!obj && url == objUrl)
                                          			QCoreApplication::exit(-1);
                                          	}, Qt::QueuedConnection);
                                          
                                          	HandleURL *URLHandler = new HandleURL();
                                          	QDesktopServices::setUrlHandler("swish", URLHandler, "handleURL");
                                          
                                          	engine.load(url);
                                          	engine.rootContext()->setContextProperty("URLHandler", URLHandler);
                                          	return app.exec();
                                          }
                                          

                                          Error:

                                          ld: framework not found AppKit
                                          clang: error: linker command failed with exit code 1 (use -v to see invocation)
                                          

                                          ---1579561823.png

                                          ---1579561786.png

                                          ---1579561723.png

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved