Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] How to extend QIOSApplicationDelegate with category on ios?



  • Hi!

    I have qt application for iOS and trying to add functions to application delegate. Guys on "this link":http://www.cutehacks.com/blog/2014/06/06/using-qt-to-build-an-omi-app-for-ios-and-android suggest to use categories to extend QIOSApplicationDelegate with own functionality.
    Like this:

    @#import "QIOSApplicationDelegate+OmiAppDelegate.h"
    #import <FacebookSDK/FacebookSDK.h>

    @implementation QIOSApplicationDelegate (OmiAppDelegate)

    • (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
      {
      return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
      }

    @end@

    But when I write own category I'm getting error that QIOSApplicationDelegate is unknown.
    What header or plugin should I include to make it known? (I searched for "qiosapplicationdelegate.h" on hard drive but didn't find it).

    Thanks!


  • Lifetime Qt Champion

    Hi,

    QIOSApplicationDelegate is in qtbase/src/plugins/platforms/ios



  • [quote author="SGaist" date="1410897385"]Hi,

    QIOSApplicationDelegate is in qtbase/src/plugins/platforms/ios[/quote]

    Thank you, I just copied this and one more header to the project and it works :)


  • Lifetime Qt Champion

    Beware that's pretty dangerous, next iteration of Qt might have this header changed so you might end up with an "invalid" delegate



  • Sure, I understand, thank you!


  • Lifetime Qt Champion

    You're welcome !

    Since you have your delegate working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)



  • If somehow has the same problem. It sufficies to add this code instead of copying/including the private header:

    @interface QIOSApplicationDelegate
    @end
    


  • Complete Code:

    In the .pro:

        ios {
            OBJECTIVE_SOURCES = ios/ios_app_delegate.mm
        }
    

    In ios/ios_app_delegate.mm:

    #import "UIKit/UIKit.h"
    
    @interface QIOSApplicationDelegate
    @end
    
    @interface QIOSApplicationDelegate (WoboqApplicationDelegate)
    @end
    
    @implementation QIOSApplicationDelegate (WoboqApplicationDelegate)
    
    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        NSLog(@"launch!");
        return YES;
    }
    
    
    @end
    
    

Log in to reply