2011-12-15 84 views
8

我嵌入在无法覆盖didFinishLaunchingWithOptions的环境(Adobe AIR)中。有没有其他的方式来获得这些选项?它们是否存储在某个全局变量中?或者是否有人知道如何在AIR中获得这些选项?在不覆盖的情况下获取启动选项didFinishLaunchingWithOptions:

我需要这个苹果推送通知服务(APNS)。

+0

Chon? – Sanniv 2012-01-16 11:10:18

+0

我想你应该看看这个,我会有一次我有时间:http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ – Michiel 2012-02-19 01:49:10

回答

11

继链接Michiel左边的路径(http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/)后,您可以创建一个类,它的init方法将一个观察者添加到UIApplicationDidFinishLaunchingNotification键中。当观察者方法执行时,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 

然后,当我的扩展上下文初始化我检查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]); 
} 

希望能帮助别人!

相关问题