iOS sdk

时间:2015-05-10 03:41:06

标签: ios objective-c xcode

我对推送通知和通知中心有疑问。我已经构建了一个应用程序,现在我想支持通知时间点击0我正在做倒计时应用程序显示游戏和标题的发布日期。 我应该使用nsnotifcation中心还是推送通知

1 个答案:

答案 0 :(得分:0)

您不需要推送通知,您可以通过UILocalNotification实现这一点。对于推送通知,您需要与服务器协调,但对于UILocalNotification,您可以在应用程序内部执行此操作,因此最好尝试使用UILocalNotification

简单的UILocalNotification

UILocalNotification* localNotification = [[UILocalNotificationalloc] init]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
localNotification.alertBody = @"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

对于带有计时器的UILocalNotification

// Get the current date
NSDate *pickerDate = [self.datePicker date];

// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.itemText.text;
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];

您可以在此处http://www.appcoda.com/ios-programming-local-notification-tutorial/

详细学习