8
我嵌入在無法覆蓋didFinishLaunchingWithOptions的環境(Adobe AIR)中。有沒有其他的方式來獲得這些選項?它們是否存儲在某個全局變量中?或者是否有人知道如何在AIR中獲得這些選項?在不覆蓋的情況下獲取啓動選項didFinishLaunchingWithOptions:
我需要這個蘋果推送通知服務(APNS)。
我嵌入在無法覆蓋didFinishLaunchingWithOptions的環境(Adobe AIR)中。有沒有其他的方式來獲得這些選項?它們是否存儲在某個全局變量中?或者是否有人知道如何在AIR中獲得這些選項?在不覆蓋的情況下獲取啓動選項didFinishLaunchingWithOptions:
我需要這個蘋果推送通知服務(APNS)。
繼鏈接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]);
}
希望能幫助別人!
Chon? – Sanniv 2012-01-16 11:10:18
我想你應該看看這個,我會有一次我有時間:http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ – Michiel 2012-02-19 01:49:10