2014-12-05 88 views
0

With UILocalNotification當鬧鈴在那個時候響鈴並行我想打開一個自定義視圖。
我正在使用以下代碼。
如何用報警打開視圖?

UILocalNotification *notification = [[UILocalNotification alloc] init]; 
if (notification == nil) 
    return; 
NSDate *dt = [NSDate dateWithTimeInterval:10 sinceDate:[NSDate date]]; 
notification.fireDate = dt; 
notification.timeZone = [NSTimeZone defaultTimeZone]; 

notification.alertBody = @"After 10Secs..."; 
notification.alertAction = @"View"; 
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

使用此代碼只會觸發通知。

enter image description here

+0

請你能澄清一個廣泛的編程指南。當你說一個自定義視圖。你的意思是通知是一個自定義視圖,或者當通知被點擊時,一個自定義視圖將顯示從你的應用程序? – 2014-12-05 10:14:16

+0

@Naughty_Ottsel是的,通知是一個自定義視圖。或者,如果可能的話,如果通知點擊一個自定義視圖打開。 – shahnilay86 2014-12-05 10:16:26

回答

0

現在澄清已設置你在找什麼。

通知不能是自定義視圖。他們由蘋果公司處理,看起來都一樣。唯一的變化是應用程序名稱,圖標和通知主體。

但是,當您計劃通知時,您可以將自定義數據存儲在通知的UserInfo屬性中。

然後,當您收到didFinishLaunchingWithOptions的委託調用時,您可以檢查選項是否爲您的通知dicitionary。檢查用戶信息,並與您的自定義視圖顯示的viewController。

蘋果對Notifications here

+0

如何獲取字典的細節?你可以給同樣的代碼嗎? – shahnilay86 2014-12-05 10:54:51

+0

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html#//apple_ref/doc/uid/TP40011210-CH7-SW15 – 2014-12-05 10:59:09

+0

- (BOOL)application :(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions UILocalNotification * localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];if(localNotif){NSString * itemName = [localNotif.userInfo objectForKey:ToDoItemKey]; [viewController displayItem:itemName]; //自定義方法 app.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1; } [window addSubview:viewController.view]; [window makeKeyAndVisible]; 返回YES; } – 2014-12-05 10:59:53

相關問題