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. Problem with a click in push notification for ios
QtWS25 Last Chance

Problem with a click in push notification for ios

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
11 Posts 2 Posters 955 Views
  • 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.
  • Q Offline
    Q Offline
    Qture
    wrote on last edited by
    #1

    In APNSApplicationDelegate.mm I have a part of an object-C code, which provides a push notification click.

    // Handle notification messages after display notification is tapped by the user.
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center
    didReceiveNotificationResponse:(UNNotificationResponse *)response
             withCompletionHandler:(void(^)(void))completionHandler {
        NSDictionary *userInfo = response.notification.request.content.userInfo;
        NSString *stack = response.notification.request.content.userInfo[@"gcm.notification.stack"];
       NSString *url = response.notification.request.content.userInfo[@"gcm.notification.url"];
      if (userInfo[kGCMMessageIDKey]) {
        NSLog(@"Message: %@", userInfo[kGCMMessageIDKey]);
      }
      // With swizzling disabled you must let Messaging know about the message, for Analytics
      // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
      // Print full message.
    NSLog(@"%@", userInfo);
    completionHandler();
    }
    

    At this moment I need to change a stackView in qml, how to make it? Thanks in advance for any advice!

    NSString *stack = response.notification.request.content.userInfo[@"gcm.notification.stack"]; 
    

    At this string needed stackView comes from Firebase, which is shown to the user.

    NSString *url = response.notification.request.content.userInfo[@"gcm.notification.url"];
    

    At this string needed url comes for webview (for a certain stackView).

    I tried some variants like hot reloading with QML, pass that two stings above through getters and setters, but still no success.

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

      Hi,

      Just an idea but you could encapsulate this through a QObject that would be set as context property of your QML engine, and then you would use it for signal/slot handling.

      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
      0
      • Q Offline
        Q Offline
        Qture
        wrote on last edited by Qture
        #3

        Hi @SGaist thank you!

        With the signal/slot handling no success yet, I have an error:

        #0	0x0000000101c933a4 in operator|(QQmlPropertyData::WriteFlag, QQmlPropertyData::WriteFlag) at /Users/qt/work/qt/qtdeclarative/src/qml/qml/qqmlpropertydata_p.h:485
        

        I'm using Q_PROPERTY, but in my code there is no any class property.

        main.cpp
        int main(int argc, char *argv[])
        {
            QtWebView::initialize();
        
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
            QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
        
            QGuiApplication app(argc, argv);
        
            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);
        
            Config SSGconfig;
            SSGconfig.init();
        
            MotivationConfig SSGmotivationConfig;
            SSGmotivationConfig.init();
        
            WorksConfig SSGworksConfig;
            SSGworksConfig.init();
        
            FCMConfig SSGFcmConfig;
            SSGFcmConfig.init();
        
            WebView SSGwebView;
            SignIn SSGsignIn;
        
            engine.rootContext()->setContextProperty("SSGwebView", &SSGwebView);
            engine.rootContext()->setContextProperty("SSGconfig", &SSGconfig);
            engine.rootContext()->setContextProperty("SSGmotivationConfig", &SSGmotivationConfig);
            engine.rootContext()->setContextProperty("SSGworksConfig", &SSGworksConfig);
            engine.rootContext()->setContextProperty("SSGFcmConfig", &SSGFcmConfig);
            engine.rootContext()->setContextProperty("SSGsignIn", &SSGsignIn);
        
            QZXing::registerQMLTypes();
        
            Application customApp;
            customApp.checkPermissions();
        
            NotificationHandler :: GetInstance () -> StartMessaging ();
        
            engine.load(url);
        
            return app.exec();
        }
        
        Config.h - short "header" of config
        class Config : public QObject
        {
            Q_OBJECT
        public:
            explicit Config(QObject *parent = nullptr);
            ~Config();
        signals:
            void sendToQml(QString);
        public slots:
            void receiveFromQml(QString);
        }
        
        Config.cpp - short config
        #include "config.h"	
        
        Config::Config(QObject *parent)
            :QObject(parent)
        {
           
        }
        
        void Config::receiveFromQml(QString stack)
        {
            emit sendToQml(stack);
        }
        
        Config::~Config()
        {
           
        }
        
        
        APNSApplicationDelegate.mm - a part of code
        // Handle notification messages after display notification is tapped by the user.
        - (void)userNotificationCenter:(UNUserNotificationCenter *)center
        didReceiveNotificationResponse:(UNNotificationResponse *)response
                 withCompletionHandler:(void(^)(void))completionHandler {
            NSDictionary *userInfo = response.notification.request.content.userInfo;
            NSString *stack = response.notification.request.content.userInfo[@"gcm.notification.stack"];
            Config SSGconfig;
            SSGconfig.receiveFromQml(stack.UTF8String);
            // NSString *url = response.notification.request.content.userInfo[@"gcm.notification.url"];
          //if (userInfo[kGCMMessageIDKey]) {
            //NSLog(@"Message ID-4: %@", userInfo[kGCMMessageIDKey]);
        
          //}
        
          // With swizzling disabled you must let Messaging know about the message, for Analytics
          // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
        
          // Print full message.
            
            NSLog(@"%@", userInfo);
            //NSLog(@"%@", [NSDictionary dictionaryWithObject:userInfo forKey:@"gcm.notification.url"]);
        
            completionHandler();
        }
        

        And a part of main.qml

        Connections {
                    target: SSGconfig
                    onSendToQml: {
                        console.log(stack)
                    }
                }
        

        I want to get the name of stackView in my qml (in console.log) but get an error, please any advice

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qture
          wrote on last edited by
          #4

          I found errors and fixed it. Now a part of the qml code looks like this:

          Connections {
          target: SSGconfig
          function onSendToQml(stack) {
          console.log(stack)
          }
          }

          С++ side's slot works correctly and in receiveFromQml I have a string value correctly, but a signal doesn't work at all.

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

            You are using two different objects. The one you set as context property is not the same as the one you use in your application delegate.

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

            Q 1 Reply Last reply
            1
            • SGaistS SGaist

              You are using two different objects. The one you set as context property is not the same as the one you use in your application delegate.

              Q Offline
              Q Offline
              Qture
              wrote on last edited by
              #6

              @SGaist sorry, where do you see different objects? Can you please tell me more what do you mean

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

                You have one in main.cpp and another one in APNSApplicationDelegate.mm

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

                Q 1 Reply Last reply
                0
                • SGaistS SGaist

                  You have one in main.cpp and another one in APNSApplicationDelegate.mm

                  Q Offline
                  Q Offline
                  Qture
                  wrote on last edited by
                  #8

                  @SGaist Is it possible to use the same object if APNSApplicationDelegate.mm links objective sources in the pro file but not in the main.cpp?

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

                    You have to retrieve the delegate and the SSGconfig object you have there.

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

                    Q 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      You have to retrieve the delegate and the SSGconfig object you have there.

                      Q Offline
                      Q Offline
                      Qture
                      wrote on last edited by
                      #10

                      @SGaist, how to retrieve the delegate?

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

                        See here.

                        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
                        0

                        • Login

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