2011-11-01 17 views
5

通知センターにすべてを設定すると、通知が表示されるので、私のアプリのローカル通知は起動しません。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で マイケル

答えて

11

、通知は通知センターによって管理されています。アプリケーションを通知センターに(プログラムで)登録するか、プログラムではなくSettings > Notificationsに移動して、通知センターを有効にする、アラートスタイルを選択するなどの適切な設定を選択する必要があります。

あなたは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。

+0

APNサービスを有効にするためにアプリIDとSSL証明書も設定する必要がありますか? – user370773

+0

回答ありがとうございます。また、UILocalNotificationDefaultSoundNameはiOS 5.0にいくつか問題があります。 –

関連する問題