2011-12-15 8 views
8

私はdidFinishLaunchingWithOptionsをオーバーライドできない環境(Adobe AIR)に組み込まれています。これらのオプションを得る他の方法はありますか?どこかのグローバル変数に格納されていますか?または誰でもAIRでこれらのオプションを取得する方法を知っていますか?didFinishLaunchingWithOptionsをオーバーライドしないで起動オプションを取得します。

Apple Push Notification Service(APNS)に必要です。

+0

Chon? – Sanniv

+0

私はあなたがこれを調べなければならないと思います。一度私は時間があります:http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ – Michiel

+0

私はあなたがこれが機能するにはANE(AIR Native Extension)が必要です。 http://www.adobe.com/devnet/air/native-extensions-for-air.html – Michiel

答えて

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]); 
} 

誰かを助ける希望!

+1

私は最終的にこれを自分自身でやり遂げました。これは魅力のように機能していると私は確信しています。 – Michiel

+0

素晴らしいコード!この小さなチップのヒントをありがとう!! – Michael

+0

'[notification userInfo]'は私のための空の辞書です= ['count == 0' – grisevg

関連する問題