Iphone 本地通知不';I don’’我不能处理iOS5
在notification center(允许应用程序显示通知)中配置所有内容后,我的应用程序的本地通知不会触发 你遇到过同样的问题吗 更多信息:Iphone 本地通知不';I don’’我不能处理iOS5,iphone,notifications,ios5,local,Iphone,Notifications,Ios5,Local,在notification center(允许应用程序显示通知)中配置所有内容后,我的应用程序的本地通知不会触发 你遇到过同样的问题吗 更多信息: 几天前,同一个应用程序使用相同的源代码编译,使用XCode 4.1和iOS 4.3 SDK编译,一切正常 此外,使用旧版本XCode和iOS SDK编译的应用程序在升级后可以在iOS5上运行 然而,使用相同代码编译的应用程序,但XCode 4.2和iOS5 SDK不起作用 你有什么想法吗? 或者iOS5有什么特别的工作吗 示例代码如下所示: UIAp
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];
}
UIApplication*app=[UIApplication-sharedApplication];
NSArray*oldNotifications=[app scheduledLocalNotifications];
//在安排新通知之前清除旧通知。
如果(0<[oldNotifications count]){
[应用程序取消所有本地通知];
}
//创建新通知
UILocalNotification*报警=[[UILocalNotification alloc]init];
如果(报警){
alarm.fireDate=日期;
alarm.timeZone=[NSTimeZone defaultTimeZone];
alarm.repeatInterval=NSDayCalendarUnit;//每天重复
alarm.alertBody=[NSString stringWithFormat:@“alert”];
[app scheduleLocalNotification:报警];
[警报解除];
}
谢谢,
Michael在iOS 5中,通知由通知中心管理。您必须(以编程方式)向通知中心注册应用程序,或(以非编程方式)转到
Settings>Notifications
并选择适当的设置,即启用通知中心、选择警报样式等
通过将应用程序放入applicationdFinishLaunching:
,可以使用以下代码(以编程方式)向通知中心注册应用程序:
// 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.我们是否还必须配置应用程序ID和SSL证书才能启用APN服务?感谢您的回答。另外,UILocalNotificationDefaultSoundName在iOS 5.0中存在一些问题。