From 449f11c11de4d1419c0e7c52f22576ecf83738bf Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Thu, 17 Sep 2015 17:01:32 -0700 Subject: [PATCH] Fixing crashes on uiactivityview and fixing lag on finding last story scroll position. --- clients/ios/Classes/EventWindow.m | 4 +- clients/ios/Classes/NBActivityItemProvider.h | 4 +- clients/ios/Classes/NBActivityItemProvider.m | 3 +- clients/ios/Classes/NewsBlurAppDelegate.m | 23 ++++---- .../ios/Classes/StoryDetailViewController.m | 53 ++++++++++--------- .../ios/NewsBlur.xcodeproj/project.pbxproj | 10 ++-- .../ios/Resources-iPad/MainWindow~ipad.xib | 11 ++-- 7 files changed, 52 insertions(+), 56 deletions(-) diff --git a/clients/ios/Classes/EventWindow.m b/clients/ios/Classes/EventWindow.m index 6fb67460b..a81ff6244 100644 --- a/clients/ios/Classes/EventWindow.m +++ b/clients/ios/Classes/EventWindow.m @@ -28,11 +28,11 @@ } - (void)sendEvent:(UIEvent *)event { - NSSet *touches = [event touchesForWindow:self]; - [super sendEvent:event]; // Call super to make sure the event is processed as usual if (!tapDetectingView) return; + + NSSet *touches = [event touchesForWindow:self]; if ([touches count] == 1) { // We're only interested in one-finger events UITouch *touch = [touches anyObject]; diff --git a/clients/ios/Classes/NBActivityItemProvider.h b/clients/ios/Classes/NBActivityItemProvider.h index c92277812..c5ca5c909 100644 --- a/clients/ios/Classes/NBActivityItemProvider.h +++ b/clients/ios/Classes/NBActivityItemProvider.h @@ -14,13 +14,11 @@ NSString *text; NSString *title; NSString *feedTitle; - NSArray *images; } - (instancetype)initWithUrl:(NSURL *)url authorName:(NSString *)authorName text:(NSString *)text title:(NSString *)title - feedTitle:(NSString *)feedTitle - images:(NSArray *)images; + feedTitle:(NSString *)feedTitle; @end diff --git a/clients/ios/Classes/NBActivityItemProvider.m b/clients/ios/Classes/NBActivityItemProvider.m index a426cacb8..570ba0092 100644 --- a/clients/ios/Classes/NBActivityItemProvider.m +++ b/clients/ios/Classes/NBActivityItemProvider.m @@ -10,13 +10,12 @@ @implementation NBActivityItemProvider -- (instancetype)initWithUrl:(NSURL *)_url authorName:(NSString *)_authorName text:(NSString *)_text title:(NSString *)_title feedTitle:(NSString *)_feedTitle images:(NSArray *)_images { +- (instancetype)initWithUrl:(NSURL *)_url authorName:(NSString *)_authorName text:(NSString *)_text title:(NSString *)_title feedTitle:(NSString *)_feedTitle { url = _url; authorName = _authorName; text = _text; title = _title; feedTitle = _feedTitle; - images = _images; return self; } diff --git a/clients/ios/Classes/NewsBlurAppDelegate.m b/clients/ios/Classes/NewsBlurAppDelegate.m index 2ffff7809..af38f9217 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.m +++ b/clients/ios/Classes/NewsBlurAppDelegate.m @@ -492,25 +492,23 @@ if (url) [activityItems addObject:url]; NSString *maybeFeedTitle = feedTitle ? [NSString stringWithFormat:@" via %@", feedTitle] : @""; if (text) text = [NSString stringWithFormat:@"



%@%@
%@", [url absoluteString], title, maybeFeedTitle, text]; -// if (images) [activityItems addObject:images]; NSMutableArray *appActivities = [[NSMutableArray alloc] init]; - [activityItems addObject:[[NBActivityItemProvider alloc] initWithUrl:(NSURL *)url - authorName:(NSString *)authorName - text:(NSString *)text - title:(NSString *)title - feedTitle:(NSString *)feedTitle - images:(NSArray *)images]]; +// [activityItems addObject:[[NBActivityItemProvider alloc] initWithUrl:(NSURL *)url +// authorName:(NSString *)authorName +// text:(NSString *)text +// title:(NSString *)title +// feedTitle:(NSString *)feedTitle]]; if (url) [appActivities addObject:[[TUSafariActivity alloc] init]]; if (url) [appActivities addObject:[[ARChromeActivity alloc] initWithCallbackURL:[NSURL URLWithString:@"newsblur://"]]]; UIActivityViewController *activityViewController = [[UIActivityViewController alloc] - initWithActivityItems:activityItems + initWithActivityItems:@[title, url, text] applicationActivities:appActivities]; [activityViewController setTitle:title]; - void (^completion)(NSString *, BOOL) = ^void(NSString *activityType, BOOL completed){ + [activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { self.isPresentingActivities = NO; - + NSString *_completedString; NSLog(@"activityType: %@", activityType); if (!activityType) return; @@ -545,8 +543,7 @@ storyHUD.labelText = _completedString; [storyHUD hide:YES afterDelay:1]; } - }; - [activityViewController setCompletionHandler:completion]; + }]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [self.masterContainerViewController presentViewController:activityViewController animated: YES completion:nil]; @@ -575,7 +572,7 @@ // [[OSKPresentationManager sharedInstance] presentActivitySheetForContent:content presentingViewController:vc popoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES options:options]; } } else { - [self.navigationController presentViewController:activityViewController animated:YES completion:nil]; + [self.navigationController presentViewController:activityViewController animated:YES completion:^{}]; } self.isPresentingActivities = YES; } diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index 0580cf2ac..b1c205754 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -397,33 +397,38 @@ - (void)scrollToLastPosition { __block NSString *storyHash = [self.activeStory objectForKey:@"story_hash"]; __weak __typeof(&*self)weakSelf = self; - [appDelegate.database inDatabase:^(FMDatabase *db) { - __strong __typeof(&*weakSelf)strongSelf = weakSelf; - if (!strongSelf) { - NSLog(@" !!! Lost strong reference to story detail vc"); - return; - } - FMResultSet *cursor = [db executeQuery:@"SELECT scroll, story_hash FROM story_scrolls s WHERE s.story_hash = ? LIMIT 1", storyHash]; - - while ([cursor next]) { - NSDictionary *story = [cursor resultDictionary]; - id scroll = [story objectForKey:@"scroll"]; - if ([scroll isKindOfClass:[NSNull class]]) { - // No scroll found - continue; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, + (unsigned long)NULL), ^(void) { + [appDelegate.database inDatabase:^(FMDatabase *db) { + __strong __typeof(&*weakSelf)strongSelf = weakSelf; + if (!strongSelf) { + NSLog(@" !!! Lost strong reference to story detail vc"); + return; } - NSInteger position = [scroll integerValue]; - NSInteger maxPosition = (NSInteger)(floor(strongSelf.webView.scrollView.contentSize.height - strongSelf.webView.frame.size.height)); - if (position > maxPosition) { - NSLog(@"Position too far, scaling back to max position: %ld > %ld", position, maxPosition); - position = maxPosition; + FMResultSet *cursor = [db executeQuery:@"SELECT scroll, story_hash FROM story_scrolls s WHERE s.story_hash = ? LIMIT 1", storyHash]; + + while ([cursor next]) { + NSDictionary *story = [cursor resultDictionary]; + id scroll = [story objectForKey:@"scroll"]; + if ([scroll isKindOfClass:[NSNull class]]) { + // No scroll found + continue; + } + NSInteger position = [scroll integerValue]; + NSInteger maxPosition = (NSInteger)(floor(strongSelf.webView.scrollView.contentSize.height - strongSelf.webView.frame.size.height)); + if (position > maxPosition) { + NSLog(@"Position too far, scaling back to max position: %ld > %ld", position, maxPosition); + position = maxPosition; + } + NSLog(@"Scrolling to %ld (%f+%f) on %@-%@", (long)position, strongSelf.webView.scrollView.contentSize.height, strongSelf.webView.frame.size.height, [story objectForKey:@"story_hash"], [strongSelf.activeStory objectForKey:@"story_title"]); + dispatch_async(dispatch_get_main_queue(), ^{ + [strongSelf.webView.scrollView setContentOffset:CGPointMake(0, position) animated:YES]; + }); } - NSLog(@"Scrolling to %ld (%f+%f) on %@-%@", (long)position, strongSelf.webView.scrollView.contentSize.height, strongSelf.webView.frame.size.height, [story objectForKey:@"story_hash"], [strongSelf.activeStory objectForKey:@"story_title"]); - [strongSelf.webView.scrollView setContentOffset:CGPointMake(0, position) animated:YES]; - } - [cursor close]; + [cursor close]; - }]; + }]; + }); } - (void)drawFeedGradient { diff --git a/clients/ios/NewsBlur.xcodeproj/project.pbxproj b/clients/ios/NewsBlur.xcodeproj/project.pbxproj index bea418c45..2f4b46f59 100755 --- a/clients/ios/NewsBlur.xcodeproj/project.pbxproj +++ b/clients/ios/NewsBlur.xcodeproj/project.pbxproj @@ -2068,7 +2068,7 @@ ORGANIZATIONNAME = NewsBlur; TargetAttributes = { 1D6058900D05DD3D006BFB54 = { - DevelopmentTeam = 6B75VSYAUJ; + DevelopmentTeam = U92APKK285; }; }; }; @@ -2584,7 +2584,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_OBJC_ARC = YES; - CODE_SIGN_IDENTITY = "iPhone Developer: Samuel Clay (3PN8E5365D)"; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -2610,7 +2610,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.newsblur.NewsBlur; PRODUCT_NAME = NewsBlur; - PROVISIONING_PROFILE = "45143eee-33c3-4c7b-82e2-4b3ac0eb2170"; + PROVISIONING_PROFILE = ""; STRIP_INSTALLED_PRODUCT = NO; TARGETED_DEVICE_FAMILY = "1,2"; "WARNING_CFLAGS[arch=*]" = "-Wall"; @@ -2624,7 +2624,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_OBJC_ARC = YES; - CODE_SIGN_IDENTITY = "iPhone Developer: Samuel Clay (3PN8E5365D)"; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -2648,7 +2648,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.newsblur.NewsBlur; PRODUCT_NAME = NewsBlur; - PROVISIONING_PROFILE = "45143eee-33c3-4c7b-82e2-4b3ac0eb2170"; + PROVISIONING_PROFILE = ""; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; diff --git a/clients/ios/Resources-iPad/MainWindow~ipad.xib b/clients/ios/Resources-iPad/MainWindow~ipad.xib index 2235adfb6..cf3d38f14 100644 --- a/clients/ios/Resources-iPad/MainWindow~ipad.xib +++ b/clients/ios/Resources-iPad/MainWindow~ipad.xib @@ -1,8 +1,8 @@ - + - + @@ -42,6 +42,7 @@ + @@ -200,6 +201,7 @@ + @@ -209,9 +211,4 @@ - - - - -