Eri*_*ric 4 ios uilocalnotification
目前,我循环遍历所有计划的本地通知,以根据userInfo字典对象中的值查找"匹配".当我设置了30多个本地通知时,这看起来非常慢.有没有办法在不遍历阵列的情况下访问单个本地通知?
这是我有的:
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *row = nil;
for (row in notificationArray) {
NSDictionary *userInfo = row.userInfo;
NSString *identifier = [userInfo valueForKey:@"movieTitle"];
NSDate *currentAlarmDateTime = row.fireDate;
if([identifier isEqualToString:myLookUpName]) {
NSLog(@"Found a match!");
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *row = " The row in notificationArray where [userInfo valueForKey:@"movieTitle"]=myLookUpName" ;
Run Code Online (Sandbox Code Playgroud)
您可以为此使用谓词,但我还没有测试过:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userInfo.movieTitle = %@", myLookUpName];
Run Code Online (Sandbox Code Playgroud)
然后使用该谓词过滤数组并获取第一个元素:
UILocalNotification *row = [[notificationArray filteredArrayUsingPredicate:predicate]objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
同样,这是未经测试的,可能无法正常工作.
编辑
如果这不起作用,您可以使用测试块:
UILocalNotification *row = [[notificationArray objectsAtIndexes:[notificationArray indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
return [[[obj userInfo]valueForKey:@"movieTitle"] isEqualToString:myLookUpName];
}]]objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4488 次 |
| 最近记录: |