2011-12-15 9 views
8

Sono incorporato in un ambiente (Adobe AIR) in cui non posso eseguire l'override di didFinishLaunchingWithOptions. C'è un altro modo per ottenere quelle opzioni? Sono memorizzati in qualche variabile globale da qualche parte? O qualcuno sa come ottenere queste opzioni in AIR?Ottieni le opzioni di avvio senza eseguire l'override didFinishLaunchingWithOptions:

Ho bisogno di questo per Apple Push Notification Service (APNS).

+0

qualsiasi fortuna Chon? – Sanniv

+0

Suppongo che dovresti esaminare questo, una volta avrò il tempo: http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ – Michiel

+0

Devo aggiungere che è necessario un ANE (AIR Native Extension) per farlo funzionare. http://www.adobe.com/devnet/air/native-extensions-for-air.html – Michiel

risposta

11

Seguendo il percorso nel collegamento Michiel a sinistra (http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/), è possibile creare una classe il cui metodo init aggiunge un osservatore alla chiave UIApplicationDidFinishLaunchingNotification. Quando viene eseguito il metodo observer, le opzioni launchO sono contenute nell'userinfo della notifica. Stavo facendo questo con le notifiche locali in modo da questa è stata la realizzazione della mia classe:

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 

Poi, quando mio contesto interno viene inizializzato ho verificare la classe NotificationChecker per vedere se l'applicazione è stata lanciata con una notifica.

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

La speranza che aiuta qualcuno!

+1

Ho finalmente avuto modo di farlo da solo e confermo che funziona come un incantesimo. – Michiel

+0

Grande codice !! Grazie mille per questo piccolo consiglio !! – Michael

+0

'[notification userInfo]' è un dizionario vuoto per me = ['count == 0' – grisevg

Problemi correlati