Fixing crashes on uiactivityview and fixing lag on finding last story scroll position.

This commit is contained in:
Samuel Clay 2015-09-17 17:01:32 -07:00
parent ad3f714259
commit 449f11c11d
7 changed files with 52 additions and 56 deletions

View file

@ -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];

View file

@ -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

View file

@ -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;
}

View file

@ -492,25 +492,23 @@
if (url) [activityItems addObject:url];
NSString *maybeFeedTitle = feedTitle ? [NSString stringWithFormat:@" via %@", feedTitle] : @"";
if (text) text = [NSString stringWithFormat:@"<html><body><br><br><hr style=\"border: none; overflow: hidden; height: 1px;width: 100%%;background-color: #C0C0C0;\"><br><a href=\"%@\">%@</a>%@<br>%@</body></html>", [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;
}

View file

@ -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 {

View file

@ -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;
};

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282b" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UIApplication">
@ -42,6 +42,7 @@
<window opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="12" customClass="EventWindow">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="blackOpaque"/>
</window>
@ -200,6 +201,7 @@
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="blackOpaque"/>
<navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="174">
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<viewControllers>
<viewController nibName="NewsBlurViewController" id="175" customClass="NewsBlurViewController">
@ -209,9 +211,4 @@
</viewControllers>
</navigationController>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>