I'm working on iOS native extension for Adobe AIR that will get device token for push notifications. Unfortunately I'm not that munch objective-C programmer and I'm not sure if there's something wrong in the code I'm using. It compiles with no problem, I can use the extension with AIR but looks like registering for notifications doesn't return neither positive nor negative effect. So what I'm trying to do is register for notifications when RegisterDevice function is called from AIR and if it does register store the device token in deviceTokenString and if it doesn't register and comes back with the error I store the error in this string. When GetToken function is called I return deviceTokenString to AIR so it's either token or error. In AIR application I launch first RegisterDevice function and later GetToken function by clicking buttons. Unfortunately I don't get neither token nor error (also popup asking for permission doesn't show up). I was also trying to put registering part in didFinishLaunchingWithOptions but it looks like didFinishLaunchingWithOptions is never launched. If you guys can have a look if the code is OK I would be really grateful. Or maybe you have any ideas what else can be wrong? I have push SSL certificate enabled in provisioning portal. Here's the code I'm using
"NativePush.m":
#import "UIKit/UIKit.h"
#import "include/FlashRuntimeExtensions.h"
@implementation NativePush
@synthesize tokenString = _tokenString;
NSString *deviceTokenString = @"";
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str =
[NSString stringWithFormat:@"%@",deviceToken];
deviceTokenString = str;
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
deviceTokenString = str;
}
void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
*numFunctionsToTest = 2;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*2);
func[0].name = (const uint8_t*)"RegisterDevice";
func[0].functionData = NULL;
func[0].function = &RegisterDevice;
func[1].name = (const uint8_t*)"GetToken";
func[1].functionData = NULL;
func[1].function = &GetToken;
*functionsToSet = func;
}
void ContextFinalizer(FREContext ctx) {
return;
}
void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet) {
*extDataToSet = NULL;
*ctxInitializerToSet = &ContextInitializer;
*ctxFinalizerToSet = &ContextFinalizer;
}
void ExtFinalizer(void* extData) {
return;
}
FREObject RegisterDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
return NULL;
}
FREObject GetToken(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
NSString* tokenS = deviceTokenString;
char* tokenChar = [tokenS UTF8String];
FREObject tokenObject = NULL;
FRENewObjectFromUTF8( strlen(tokenChar)+1 , (const uint8_t*)tokenChar, &tokenObject);
return tokenObject;
}
@end
and header file "NativePush.h":
import "Foundation/Foundation.h"
import "include/FlashRuntimeExtensions.h"
@interface NativePush : NSObject
@property (nonatomic, retain) NSString* tokenString;
FREObject RegisterDevice(
FREContext ctx,
void* funcData,
uint32_t argc,
FREObject arg[]
);
FREObject GetToken(
FREContext ctx,
void* funcData,
uint32_t argc,
FREObject arg[]
);
void ContextInitializer(
void* extData,
const uint8_t* ctxType,
FREContext ctx,
uint32_t* numFunctionsToTest,
const FRENamedFunction** functionsToSet
);
void ContextFinalizer(FREContext ctx);
void ExtInitializer(
void** extDataToSet,
FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet
);
void ExtFinalizer(void* extData);
@end