Problem with a click in push notification for ios
-
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.
-
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.
-
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
-
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.
-
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.
-
You have one in main.cpp and another one in APNSApplicationDelegate.mm
-
You have to retrieve the delegate and the SSGconfig object you have there.