diff --git a/External/Pearl b/External/Pearl index d33d38b9..f81514bf 160000 --- a/External/Pearl +++ b/External/Pearl @@ -1 +1 @@ -Subproject commit d33d38b91a7741b04d1bf5a08145ed4983888dc7 +Subproject commit f81514bfd87773c6b1ea202520d75841c159ce9f diff --git a/MasterPassword/MPAppDelegate_Key.m b/MasterPassword/MPAppDelegate_Key.m index 6ff670cf..ea11453d 100644 --- a/MasterPassword/MPAppDelegate_Key.m +++ b/MasterPassword/MPAppDelegate_Key.m @@ -25,8 +25,8 @@ static NSDictionary *keyQuery(MPUserEntity *user) { - (MPKey *)loadSavedKeyFor:(MPUserEntity *)user { - NSData *key = [PearlKeyChain dataOfItemForQuery:keyQuery(user)]; - if (key) + NSData *keyData = [PearlKeyChain dataOfItemForQuery:keyQuery(user)]; + if (keyData) inf(@"Found key in keychain for: %@", user.userID); else { @@ -34,20 +34,20 @@ static NSDictionary *keyQuery(MPUserEntity *user) { inf(@"No key found in keychain for: %@", user.userID); } - return [MPAlgorithmDefault keyFromKeyData:key]; + return [MPAlgorithmDefault keyFromKeyData:keyData]; } - (void)storeSavedKeyFor:(MPUserEntity *)user { if (user.saveKey) { - NSData *existingKey = [PearlKeyChain dataOfItemForQuery:keyQuery(user)]; + NSData *existingKeyData = [PearlKeyChain dataOfItemForQuery:keyQuery(user)]; - if (![existingKey isEqualToData:self.key.keyData]) { + if (![existingKeyData isEqualToData:self.key.keyData]) { inf(@"Saving key in keychain for: %@", user.userID); [PearlKeyChain addOrUpdateItemForQuery:keyQuery(user) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys: - self.key, (__bridge id)kSecValueData, + self.key.keyData, (__bridge id)kSecValueData, #if TARGET_OS_IPHONE (__bridge id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly, (__bridge id)kSecAttrAccessible, #endif diff --git a/MasterPassword/iOS/MPMainViewController.m b/MasterPassword/iOS/MPMainViewController.m index 61baa9c3..0f47c258 100644 --- a/MasterPassword/iOS/MPMainViewController.m +++ b/MasterPassword/iOS/MPMainViewController.m @@ -692,6 +692,7 @@ - (IBAction)action:(id)sender { [PearlSheet showSheetWithTitle:nil message:nil viewStyle:UIActionSheetStyleAutomatic + initSheet:nil tappedButtonBlock:^(UIActionSheet *sheet, NSInteger buttonIndex) { if (buttonIndex == [sheet cancelButtonIndex]) return; diff --git a/MasterPassword/iOS/MPSearchDelegate.h b/MasterPassword/iOS/MPSearchDelegate.h index 2caa2ef5..0bb918e0 100644 --- a/MasterPassword/iOS/MPSearchDelegate.h +++ b/MasterPassword/iOS/MPSearchDelegate.h @@ -22,13 +22,13 @@ typedef enum { @interface MPSearchDelegate : NSObject -@property (strong, nonatomic) NSDateFormatter *dateFormatter; -@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; -@property (strong, nonatomic) NSString *query; -@property (strong, nonatomic) UILabel *tipView; +@property (strong, nonatomic) NSDateFormatter *dateFormatter; +@property (strong, readonly) NSFetchedResultsController *fetchedResultsController; +@property (strong, nonatomic) NSString *query; +@property (strong, nonatomic) UILabel *tipView; @property (weak, nonatomic) IBOutlet id delegate; @property (strong, nonatomic) IBOutlet UISearchDisplayController *searchDisplayController; -@property (weak, nonatomic) IBOutlet UIView *searchTipContainer; +@property (weak, nonatomic) IBOutlet UIView *searchTipContainer; @end diff --git a/MasterPassword/iOS/MPSearchDelegate.m b/MasterPassword/iOS/MPSearchDelegate.m index e6500610..2b2d3354 100644 --- a/MasterPassword/iOS/MPSearchDelegate.m +++ b/MasterPassword/iOS/MPSearchDelegate.m @@ -17,11 +17,13 @@ @end -@implementation MPSearchDelegate +@implementation MPSearchDelegate { + + NSFetchedResultsController *_fetchedResultsController; +} @synthesize tipView; @synthesize query; @synthesize dateFormatter; -@synthesize fetchedResultsController; @synthesize delegate; @synthesize searchDisplayController; @synthesize searchTipContainer; @@ -35,13 +37,6 @@ self.dateFormatter.dateStyle = NSDateFormatterShortStyle; self.query = @""; - NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([MPElementEntity class])]; - fetchRequest.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"uses_" ascending:NO]]; - self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest - managedObjectContext:[MPAppDelegate managedObjectContextIfReady] - sectionNameKeyPath:nil cacheName:nil]; - self.fetchedResultsController.delegate = self; - self.tipView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 170)]; self.tipView.textAlignment = UITextAlignmentCenter; self.tipView.backgroundColor = [UIColor clearColor]; @@ -62,6 +57,23 @@ return self; } +- (NSFetchedResultsController *)fetchedResultsController { + + if (!_fetchedResultsController) { + NSManagedObjectContext *moc = [MPAppDelegate managedObjectContextIfReady]; + if (!moc) + return nil; + + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([MPElementEntity class])]; + fetchRequest.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"uses_" ascending:NO]]; + _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:moc + sectionNameKeyPath:nil cacheName:nil]; + _fetchedResultsController.delegate = self; + } + + return _fetchedResultsController; +} + - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { UITableView *tableView = self.searchDisplayController.searchResultsTableView; @@ -175,15 +187,17 @@ if (![self.fetchedResultsController performFetch:&error]) err(@"Couldn't fetch elements: %@", error); - NSArray *subviews = self.searchDisplayController.searchBar.superview.subviews; - NSUInteger overlayIndex = [subviews indexOfObject:self.searchDisplayController.searchBar] + 1; - UIView *overlay = [subviews count] > overlayIndex? [subviews objectAtIndex:overlayIndex]: nil; - if (overlay == self.searchDisplayController.searchResultsTableView || ![overlay isKindOfClass:[UIControl class]]) - overlay = nil; - if (self.tipView.superview != overlay) { - [self.tipView removeFromSuperview]; - [overlay addSubview:self.tipView]; - } + [self.searchDisplayController.searchBar.superview enumerateSubviews:^(UIView *subview, BOOL *stop, BOOL *recurse) { + CGRect searchBarFrame = self.searchDisplayController.searchBar.frame; + if ([subview isKindOfClass:[UIControl class]] && + CGPointEqualToPoint( + CGPointDistanceBetweenCGPoints(searchBarFrame.origin, subview.frame.origin), + CGPointMake(0, searchBarFrame.size.height))) { + [self.tipView removeFromSuperview]; + [subview addSubview:self.tipView]; + *stop = YES; + } + } recurse:NO]; } // See MP-14, also crashes easily on internal assertions etc.. diff --git a/MasterPassword/iOS/MPUnlockViewController.m b/MasterPassword/iOS/MPUnlockViewController.m index d9c64be9..b81dc5da 100644 --- a/MasterPassword/iOS/MPUnlockViewController.m +++ b/MasterPassword/iOS/MPUnlockViewController.m @@ -724,6 +724,7 @@ [PearlSheet showSheetWithTitle:targetedUser.name message:nil viewStyle:UIActionSheetStyleBlackTranslucent + initSheet:nil tappedButtonBlock:^(UIActionSheet *sheet, NSInteger buttonIndex) { if (buttonIndex == [sheet cancelButtonIndex]) return;