【发布时间】:2014-10-15 07:37:37
【问题描述】:
我想根据来自服务器的通知计数安排多个通知,它应该一个接一个地触发...
如果count == 4,应该触发四个通知..
我是 iOS 初学者
这是我的代码:
- (void)sendNotification {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.alertBody = @"We have fresh vegetables and fruits!";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
- (void)test {
NSData *allNoteData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"hiberryfarm.com/mobile/all_notification.php"]];
NSError *error;
NSMutableDictionary *allNote = [NSJSONSerialization JSONObjectWithData:allNoteData options:NSJSONReadingMutableContainers error:&error];
NSArray *Notifications = allNote[@"notifications"];
NSUInteger *noteCount = [Notifications count];
if (noteCount > 0) {
for ( NSDictionary *noteObj in Notifications ) {
[self sendNotification];
}
}
【问题讨论】:
-
几件事 1) 你已经尝试过什么?请分享您已经完成的代码,以向我们展示您在提出问题之前自己尝试过此操作,我们很乐意提供帮助,但您需要表明您首先尝试自己解决此问题。 2) 这与
xcodeIDE 无关,因为您使用xcode并不意味着您应该使用该标签,所以我删除了该标签。欢迎使用 stackoverflow。 -
同意@Popeye!您需要更加准确,并就您已经做过的事情向我们提供提示,否则将无法真正提供帮助。
-
感谢您的快速回复。不要介意他们在那里犯错。下面是我尝试的代码 appviewcontroller.m
-
- (void)sendNotification { UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; localNotification.alertBody = @"我们有新鲜蔬菜和水果!"; localNotification.timeZone = [NSTimeZone defaultTimeZone]; localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; }
-
请将代码添加到问题中。谢谢
标签: objective-c ios7 uilocalnotification