簡體   English   中英

本地通知在iOS5上不起作用

[英]Local Notification doesn't work on iOS5

在通知中心配置所有內容(允許應用程序顯示通知)后,我的應用程序的本地通知不會觸發。

你遇到同樣的問題嗎?

更多信息:

  1. 幾天前使用相同的源代碼編譯的相同應用程序,使用XCode 4.1和iOS 4.3 SDK編譯,一切運行良好。

  2. 此外,使用舊版XCode和iOS SDK編譯的應用程序可以在升級后在iOS5上運行。

但是,使用相同代碼編譯的應用程序,但XCode 4.2和iOS5 SDK不起作用。

你有什么想法? 或者iOS5有什么特別的工作嗎?

示例代碼如下:

UIApplication *app = [UIApplication sharedApplication];
NSArray *oldNotifications = [app scheduledLocalNotifications];

// Clear out the old notification before scheduling a new one.
if (0 < [oldNotifications count]) {

    [app cancelAllLocalNotifications];
} 

// Create a new notification
UILocalNotification *alarm = [[UILocalNotification alloc] init];
if (alarm) {

    alarm.fireDate = theDate;
    alarm.timeZone = [NSTimeZone defaultTimeZone];
    alarm.repeatInterval = NSDayCalendarUnit; //repeat every day
    alarm.alertBody = [NSString stringWithFormat:@"alert"];     
    [app scheduleLocalNotification:alarm];
    [alarm release];
}

謝謝,邁克爾

在iOS 5中,通知由通知中心管理。 您必須使用通知中心(以編程方式)注冊您的應用程序,或(非編程)轉到Settings > Notifications並選擇適當的設置,例如啟用通知中心,選擇警報樣式等。

您可以使用以下代碼通過Notification Center(以編程方式)向applicationDidFinishLaunching: ::

// Although Register For Remote Notifications is not required for Local Notifications,
// but in iOS 5's Notifications, we have to register otherwise the system doesn't register/recognize
// the notifications posted from the application. Note that this behavior is not documented
// as of Oct 2011, and it's possible that it's a bug and will be handled in the future releases.

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
 UIRemoteNotificationTypeAlert |
 UIRemoteNotificationTypeSound];

HTH。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM