我嵌入在无法覆盖didFinishLaunchingWithOptions的环境(Adobe AIR)中。还有其他方法可以得到这些选择吗?它们存储在某个全局变量中的某个地方吗?还是有人知道如何在AIR中获得这些选项?
苹果推送通知服务(APNS)需要此功能。
最佳答案
按照链接Michiel左侧(http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/)的路径,您可以创建一个类,该类的init方法将观察者添加到UIApplicationDidFinishLaunchingNotification键。当执行观察者方法时,launchOptions将包含在通知的userInfo中。我正在使用本地通知来执行此操作,因此这是我的类(class)的实现:
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/