【问题标题】:iPhone : Is it possible to get each different text in alert for local notification?iPhone:是否可以在本地通知警报中获取每个不同的文本?
【发布时间】:2012-02-26 19:13:55
【问题描述】:

我的应用程序用于从数据库中选择不同的文本数据。我们有每天显示本地通知的功能。

我正在使用以下代码:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = [itemDate addTimeInterval:-(minutesBefore*60)];
localNotif.timeZone = [NSTimeZone defaultTimeZone];

localNotif.alertBody = @"Hey";   // Can I select random message for this notification?
localNotif.alertAction = NSLocalizedString(@"View Details", nil);

localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

NSDictionary *infoDict = [NSDictionary dictionaryWithObject:item.eventName forKey:ToDoItemKey];
localNotif.userInfo = infoDict;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];

现在是否可以为本地通知显示不同的文本数据?怎么样?

【问题讨论】:

  • 你能举一个你想要显示的不同文本的例子吗?
  • @Leena:随便说一句:localNotif.alertBody = @"Hey";否则 localNotif.alertBody = @"你好"; else localNotif.alertBody = @"哦,太好了";
  • 创建一个字符串数组,然后随机选择字符串并将其分配给您的 localnotification.alertbody
  • 但我每天都在重复。所以它会每天显示相同的消息。我想显示不同的消息。
  • 我不认为这是可能的。

标签: iphone objective-c cocoa-touch ios4 uilocalnotification


【解决方案1】:

您可以创建一个字符串数组,每次选择一个随机对象并将其分配给 localnotif body 。

【讨论】:

  • @ :当您设置本地通知时,上述代码将只运行一次。所以它会选择一条消息,第二天它会显示相同的......我想要随机的地方。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多