Use Firebase SDK on iOs (push notifications)



  • Hi,

    has someone of you successfully used the Firebase SDK for integrating push notifications? I mostly followed this guide here: https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/AppDelegate.m

    The relevant parts are looking like this:

    my AppDelegate:

    #import "FirebaseInstanceID.h"
    #import "FirebaseMessaging.h"
    #import "FirebaseAnalytics.h"
    #import <FIRApp.h>
    
    @interface QIOSApplicationDelegate
    @end
    //add a category to QIOSApplicationDelegate
    @interface QIOSApplicationDelegate (QPushNotificationDelegate)
    @end
    
    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // Register for remote notifications. This shows a permission dialog on first run, to
            // show the dialog at a more appropriate time move this registration accordingly.
            if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
                // iOS 7.1 or earlier. Disable the deprecation warnings.
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
                UIRemoteNotificationType allNotificationTypes =
                (UIRemoteNotificationTypeSound |
                 UIRemoteNotificationTypeAlert |
                 UIRemoteNotificationTypeBadge);
                [application registerForRemoteNotificationTypes:allNotificationTypes];
    #pragma clang diagnostic pop
            } else {
                // iOS 8 or later
                // [START register_for_notifications]
                if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
                    UIUserNotificationType allNotificationTypes =
                    (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
                    UIUserNotificationSettings *settings =
                    [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
                    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
                }
    
    [[UIApplication sharedApplication] registerForRemoteNotifications];
                // [END register_for_notifications]
            }
    // [START configure_firebase]
        [FIRApp configure];
        // [END configure_firebase]
        // Add observer for InstanceID token refresh callback.
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                     name:kFIRInstanceIDTokenRefreshNotification object:nil];
    }
    

    my *.pro file:

    MAKE_LFLAGS += -F$$PWD/ext/libraries/ios/Firebase/Analytics
        QMAKE_LFLAGS += -F$$PWD/ext/libraries/ios/Firebase/Messaging
        QMAKE_LFLAGS += -ObjC
    
    
        INCLUDEPATH += $$PWD/ext/libraries/ios/Firebase/Analytics/FirebaseAnalytics.framework/Headers
        INCLUDEPATH += $$PWD/ext/libraries/ios/Firebase/Analytics/FirebaseInstanceID.framework/Headers
        INCLUDEPATH += $$PWD/ext/libraries/ios/Firebase/Messaging/FirebaseMessaging.framework/Headers
        INCLUDEPATH += $$PWD/ext/libraries/ios/Firebase/Analytics/FirebaseCore.framework/Headers
        LIBS +=-framework FirebaseAnalytics
        LIBS +=-framework FirebaseCore
        LIBS +=-framework FirebaseInstanceID
        LIBS +=-framework GoogleInterchangeUtilities
        LIBS +=-framework GoogleSymbolUtilities
        LIBS +=-framework GoogleUtilities
        LIBS +=-framework FirebaseMessaging
        LIBS +=-framework GoogleIPhoneUtilities
        LIBS +=-framework AddressBook
        LIBS += -lsqlite3
    

    Unfortunately I always get:

    Use of undeclared identifier FIRApp
    

    when compiling. Does anyone have an idea on how to fix that?



  • Hi!

    V-Play Engine offers several plugins for integrating push notifications in your Qt app, for example with the Google Cloud Messaging service.
    A Firebase plugin is currently being implemented and will be coming soon as well.

    Best,
    GT



  • Here is my solution:
    Create a directory "ios/CocoaPods" inside root path of the Qt Project
    Create inside this directory an Xcode project "Empty" (just autogenerate a single view iOS project with Xcode and save here)
    Create a file "Podfile" with the following content:
    target 'Empty' do
    pod 'Firebase/Core'
    pod 'Firebase/Auth'
    pod 'Firebase/Messaging'
    pod 'Firebase/Database'
    pod 'Firebase/Crash'
    end

    Run "pod install"; and inside the "CocoaPods" there will be a directory "Pods" with generated Frameworks.
    In your .pro add the following lines to include frameworks:
    LIBS += -F$$PWD/ios/CocoaPods/Pods/FirebaseCore/Frameworks -framework FirebaseCore \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseAnalytics/Frameworks -framework FirebaseAnalytics \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseAuth/Frameworks -framework FirebaseAuth \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseCrash/Frameworks -framework FirebaseCrash \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseDatabase/Frameworks -framework FirebaseDatabase \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseInstanceID/Frameworks -framework FirebaseInstanceID \
    -F$$PWD/ios/CocoaPods/Pods/FirebaseMessaging/Frameworks -framework FirebaseMessaging

    INCLUDEPATH += $$PWD/ios/CocoaPods/Pods/FirebaseCore/Frameworks/FirebaseCore.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseAuth/Frameworks/FirebaseAuth.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseCrash/Frameworks/FirebaseCrash.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseDatabase/Frameworks/FirebaseDatabase.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/Headers \
    $$PWD/ios/CocoaPods/Pods/FirebaseMessaging/Frameworks/FirebaseMessaging.framework/Headers
    XCODE_EXTRAS.files = ios/GoogleService-Info.plist
    QMAKE_BUNDLE_DATA += XCODE_EXTRAS


Log in to reply
 

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