[Interest] Qt Desktop push notifications, can't get to NSApplication?

Wesley Krasko wesblake at gmail.com
Tue Jan 19 21:49:49 CET 2021


Hi. So we are trying to add push notifications to an existing Qt Desktop
application. Mac OS is first priority.

However, I can't figure out how to get to NSApplication to register to APN.
I looked here, although it's for iOS and Android:

https://github.com/gympulsr/qt-pushnotifications

Simple code so converted to MacOS, mostly changed the mm file:

#include <AppKit/NSApplication.h>

#include "pushnotification.h"


@interface QMacOSApplicationDeligate

@end

//add a category to AppDelegate

@interface QMacOSApplicationDeligate (QPushNotificationDelegate)

@end



@implementation QMacOSApplicationDeligate (QPushNotificationDelegate)

- (BOOL)application:(NSApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {



    //-- Set Notification

    [application registerForRemoteNotifications];

    return YES;

}



- (void)application:(NSApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{

    NSLog(@"Did Register for Remote Notifications with Device Token
(%@)", deviceToken);



//    const unsigned *tokenBytes = (const unsigned*)[deviceToken bytes];

//    NSString *tokenStr = [NSString
stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",

//                          ntohl(tokenBytes[0]),
ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),

//                          ntohl(tokenBytes[3]),
ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),

//                          ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

//    PushNotificationRegistrationTokenHandler::instance()->setAPNSRegistrationToken(QString::fromNSString(tokenStr));

}



- (void)application:(NSApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

    NSLog(@"Did Fail to Register for Remote Notifications");

    NSLog(@"%@, %@", error, error.localizedDescription);



}

@end

But, I'm getting exactly this issue, looks like they were trying to do
almost the same thing. I can't figure out how I can do this, any
suggestions?
https://interest.qt-project.narkive.com/6v9o61We/objective-c-category-for-qcocoaapplicationdelegate-undefined-symbols


-- 
Wes Krasko
www.worldwidewes.com
www.kraskofamily.com
"Stay away from negative people. They have a problem for every solution."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210119/82b2c276/attachment.html>


More information about the Interest mailing list