获取启动选项而不覆盖didFinishLaunchingWithOptions:

Cho*_*rry 9 air iphone flash apple-push-notifications

我嵌入在一个环境(Adobe AIR)中,我无法覆盖didFinishLaunchingWithOptions.有没有其他方法可以获得这些选择?它们存储在某个地方的某个全局变量中吗?或者有人知道如何在AIR中获得这些选项吗?

我需要这个Apple推送通知服务(APNS).

小智 11

按照Michiel离开的链接路径(http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/),您可以创建一个类,其init方法将一个观察者添加到UIApplicationDidFinishLaunchingNotification键.执行observer方法时,launchOptions将包含在通知的userInfo中.我是用本地通知做的,所以这是我的类的实现:

static BOOL _launchedWithNotification = NO;
static UILocalNotification *_localNotification = nil;

@implementation NotificationChecker

+ (void)load
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createNotificationChecker:)
               name:@"UIApplicationDidFinishLaunchingNotification" object:nil];

}

+ (void)createNotificationChecker:(NSNotification *)notification
{
    NSDictionary *launchOptions = [notification userInfo] ;

    // This code will be called immediately after application:didFinishLaunchingWithOptions:.    
    UILocalNotification *localNotification = [launchOptions objectForKey: @"UIApplicationLaunchOptionsLocalNotificationKey"];
    if (localNotification) 
    {
        _launchedWithNotification = YES;
        _localNotification = localNotification;
    }
    else 
    {
        _launchedWithNotification = NO;
    }
}

+(BOOL) applicationWasLaunchedWithNotification
{
    return _launchedWithNotification;
}

+(UILocalNotification*) getLocalNotification
{
    return _localNotification;
}

@end
Run Code Online (Sandbox Code Playgroud)

然后,当我的扩展上下文被初始化时,我检查NotificationChecker类以查看是否通过通知启动了应用程序.

BOOL appLaunchedWithNotification = [NotificationChecker applicationWasLaunchedWithNotification];
if(appLaunchedWithNotification)
{
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;

    UILocalNotification *notification = [NotificationChecker getLocalNotification];
    NSString *type = [notification.userInfo objectForKey:@"type"];

    FREDispatchStatusEventAsync(context, (uint8_t*)[@"notificationSelected" UTF8String], (uint8_t*)[type UTF8String]);
}
Run Code Online (Sandbox Code Playgroud)

希望有人帮助!