我嵌入到一个环境 (Adobe AIR) 中,无法覆盖 didFinishLaunchingWithOptions。还有其他方法可以获得这些选项吗?它们是否存储在某个全局变量中?或者有人知道如何在 AIR 中获取这些选项吗?
我需要这个用于 Apple 推送通知服务 (APNS)。
最佳答案
沿着 Michiel left 链接 ( 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]);
}
希望对某人有帮助!
关于iphone - 获取启动选项而不覆盖 didFinishLaunchingWithOptions :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8525569/