我嵌入在一个环境(Adobe AIR)中,我无法覆盖didFinishLaunchingWithOptions。有没有其他方法可以获得这些选择?它们存储在某个地方的某个全局变量中吗?或者有人知道如何在AIR中获得这些选项吗?
我需要Apple推送通知服务(APNS)。
答案 0 :(得分: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
然后,当我的扩展上下文被初始化时,我检查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]);
}
希望能帮助别人!