2011-12-15 16 views
8

didFinishLaunchingWithOptions'ı geçersiz kılmadığım bir ortamda (Adobe AIR) gömülüyorum. Bu seçenekleri almak için başka bir yolu var mı? Bazı küresel değişkenlerde bir yerde mi depolanıyorlar? Ya da AIR'de bu seçenekleri nasıl alacağını bilen var mı?Geçersiz kılmadan başlatma seçeneklerini edinin didFinishLaunchingWithOptions:

Apple Push Notification Service (APNS) için buna ihtiyacım var.

+0

herhangi bir şans Chon? – Sanniv

+0

Sanırım buna bakmalısın, ben bir zamanım olacak: http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ – Michiel

+0

Yapman gerekeni eklemeliyim. Bunun çalışması için bir ANE (AIR Native Extension). http://www.adobe.com/devnet/air/native-extensions-for-air.html – Michiel

cevap

11

Michiel'in solundaki (http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/) yoldaki yolu takip ederek, init yönteminin UIApplicationDidFinishLaunchingNotification anahtarına bir gözlemci ekleyen bir sınıf oluşturabilirsiniz. Gözlemci yöntemi yürütüldüğünde, launchOptions bildirimin userInfo dosyasında yer alacaktır. Ben yerel bildirimleri ile bu yapıyordu bu benim sınıfın uygulanması idi: Uzantımın bağlam başlatıldığında

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 

Sonra uygulama bildirimle başlatıldı görmek için NotificationChecker sınıfını kontrol edin.

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

Birilerine yardım etmesini umarız!

+1

Sonunda kendimi yapıyorum ve bunun bir çekicilik gibi çalıştığını doğrularım. – Michiel

+0

Harika bir kod! Bu küçük bahşiş için teşekkürler yığınları! – Michael

+0

'[notification userInfo]' benim için boş bir sözlüktür = ['count == 0' – grisevg

İlgili konular