且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

本地通知在iOS5上不起作用

更新时间:2023-01-02 22:35:18

在iOS 5中,通知由Notification Center管理。您必须在通知中心(以编程方式)注册您的应用程序,或(以非编程方式)转到设置>通知并选择适当的设置,例如启用通知中心,选择提醒方式等。

In iOS 5, notifications are managed by Notification Center. You have to register your application with the Notification Center (programmatically), or (non-programmatically) go to Settings > Notifications and select appropriate settings i.e. enable Notification Center, select Alert Style, and others.

您可以使用以下代码注册您的应用程序使用Notification Center(以编程方式),将其放入 applicationDidFinishLaunching:

You can use following piece of code to register your application with Notification Center (programmatically), by putting it in 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。