如何优化 UILocalNotification 流程

发布于 2024-10-11 17:52:48 字数 1010 浏览 2 评论 0原文

我正在尝试使用实体上的获取请求发送多个 localNofications 虽然这段代码工作正常

   NSFetchRequest *myRequest = [[NSFetchRequest alloc] init];
   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"active == YES"];
  [myRequest setEntity:[NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]];
  [myRequest setPredicate:predicate];
  NSError *error = nil;
  NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest: myRequest error: &error];
  if (fetchedObjects == nil){
 // Deal with error...
 }

// We fill the NSMutableArray with the values of the fetch
self.activeList = [[NSMutableArray alloc] initWithArray:[fetchedObjects valueForKey:@"textbody"]];
[self scheduleAlarms:[self.activeList objectAtIndex:0]];
[fetchedObjects release]; //this line crashes the app

1) 如果我释放 fetchedObjects,应用程序就会崩溃。我不是应该释放它吗?

2)我可以使用 localNotif.userinfo 来优化代码,而不是调用方法来使用 activeList 中的字符串安排每个 localNotification 吗?我不知道该怎么做。

谢谢,

迈克

I'm trying to send multiple localNofications using a fetch request on an entity
And though this code works fine

   NSFetchRequest *myRequest = [[NSFetchRequest alloc] init];
   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"active == YES"];
  [myRequest setEntity:[NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]];
  [myRequest setPredicate:predicate];
  NSError *error = nil;
  NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest: myRequest error: &error];
  if (fetchedObjects == nil){
 // Deal with error...
 }

// We fill the NSMutableArray with the values of the fetch
self.activeList = [[NSMutableArray alloc] initWithArray:[fetchedObjects valueForKey:@"textbody"]];
[self scheduleAlarms:[self.activeList objectAtIndex:0]];
[fetchedObjects release]; //this line crashes the app

1) if I release fetchedObjects, the app crashes. Aren't I supposed to release it ?

2) Could I use the localNotif.userinfo to optimize the code instead of calling a method to schedule each localNotification with the strings in my activeList ? I can't figure out how to do it.

Thanks,

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2024-10-18 17:52:48

1)executeFetchRequest返回一个自动释放的NSArray,你不需要手动释放它

2)不清楚你想优化什么......

1) executeFetchRequest returns an autoreleased NSArray, you don't need to release it manually

2) not clear what do you want to optimize...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文