这是我为Event设置本地通知的代码,但它显示了不同iphone的不同文本,例如,对于某些iPhone,它显示" Slide for more"对某些人来说,它显示了"触摸打开"我在哪里设置"查看详细信息"消息:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.alertTitle = self.titleCell.propertyValue;
localNotification.alertBody = self.titleCell.propertyValue;
localNotification.alertAction = @"view details";
答案 0 :(得分:-1)
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"This local notification"
delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[notificationAlert show];//use latest alert action
}
<强> yourControler.m 强>
-(IBAction)startLocalNotification { // Bind this method to UIButton action
NSLog(@"startLocalNotification");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
notification.alertBody = @"This is local notification!";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 10;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
您需要注册本地通知
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}