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

标签 iphone flash air apple-push-notifications

我嵌入到一个环境 (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/

相关文章:

iphone - 如何使用 Bonjour 跨子网宣传服务?

ios - 从 PC 上的 iPhone App 的文档文件夹下载创建的文件

ios - 在iPad上的File.browseForSave()

flash - 生成大量位图时,创建的位图会变成全黑

android - 是什么导致此错误 : "SDK component at air/android/device/Runtime.apk is out of date"

iphone - 从库中获取图像并扫描二维码

ios - 如何通过 SwiftUI 中的按钮点击显示菜单?

javascript - Flash VS jQuery 用于 RIA 开发 : Which one is better to use and for what reasons?

android - 如何从 Bintray 或 Maven 将 Java 库包含到 Adob​​e Air(Android 的 native 扩展)项目中

apache-flex - Actionscript 的 Number 类的 toFixed() 方法返回奇怪的值