I’m tying to add support for push notifications. I want to add this objective-c call to my code:
Code:
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@“Did Register for Remote Notifications with Device Token (%@)”, deviceToken);
}
I’m assuming that this should be implemented as part of the SDLUIKitDelegate class. Can I add to a class that is already complied in a library?
Or can get this callback registered in some other way?
You can create a subclass of SDLUIKitDelegate and implement it there. I believe it should work as long as you create a SDLUIKitDelegate category to override +(NSString *)getAppDelegateClassName to return the class name of your subclass.
(This is according to comments in SDL_uikitappdelegate.m ? I haven?t tried it myself.)> On Nov 12, 2015, at 11:00 AM, Starg wrote:
Hi,
I’m tying to add support for push notifications. I want to add this objective-c call to my code:
Code:
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@“Did Register for Remote Notifications with Device Token (%@)”, deviceToken);
}
I’m assuming that this should be implemented as part of the SDLUIKitDelegate class. Can I add to a class that is already complied in a library?
Or can get this callback registered in some other way?
I’ve successfully added the new call to the SDL appDelegate. Here’s how for anyone else interested:
Code:
// include the header when the app delegate code is #import “…/…/…/externalLibs/SDL2iOS/include/SDL_uikitappdelegate.h”
// Add a ‘category’ to the SDL app delegate class @interface SDLUIKitDelegate (extra)
{
} @end
// Add a method to the class. @implementation SDLUIKitDelegate (extra)
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@“Did Register for Remote Notifications with Device Token (%@)”, deviceToken);
}
(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@“Did Fail to Register for Remote Notifications”);
NSLog(@"%@, %@", error, error.localizedDescription);
} @end
I had to copy SDL_uikitappdelegate.h to the SDL include files so it can be imported and for the class to be found. Not sure if there’s a better way round this.
But the above works fine.
I didn’t need to override the getAppDelegateClassName though.
Oh, one other thing. I renamed my main.cpp to main.mm and added this code to the top. I’ll move it so somewhere more ‘proper’, but I thought I’d mention it if anyone else is trying to get this up and running quickly.