mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
#1231 (sharing crash)
- Now extracts the URL title and sets that when sharing, in addition to any user comments.
This commit is contained in:
parent
3f4c084f94
commit
599ad28c99
1 changed files with 17 additions and 1 deletions
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
@interface ShareViewController () <NSURLSessionDelegate>
|
@interface ShareViewController () <NSURLSessionDelegate>
|
||||||
|
|
||||||
|
@property (nonatomic, strong) NSString *itemTitle;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ShareViewController
|
@implementation ShareViewController
|
||||||
|
@ -26,6 +28,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didSelectPost {
|
- (void)didSelectPost {
|
||||||
|
self.itemTitle = nil;
|
||||||
|
|
||||||
NSItemProvider *itemProvider = [self providerWithURL];
|
NSItemProvider *itemProvider = [self providerWithURL];
|
||||||
|
|
||||||
NSLog(@"ShareExt: didSelectPost");
|
NSLog(@"ShareExt: didSelectPost");
|
||||||
|
@ -55,6 +59,12 @@
|
||||||
for (NSExtensionItem *extensionItem in self.extensionContext.inputItems) {
|
for (NSExtensionItem *extensionItem in self.extensionContext.inputItems) {
|
||||||
for (NSItemProvider *itemProvider in extensionItem.attachments) {
|
for (NSItemProvider *itemProvider in extensionItem.attachments) {
|
||||||
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
|
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
|
||||||
|
self.itemTitle = extensionItem.attributedTitle.string;
|
||||||
|
|
||||||
|
if (!self.itemTitle.length) {
|
||||||
|
self.itemTitle = extensionItem.attributedContentText.string;
|
||||||
|
}
|
||||||
|
|
||||||
return itemProvider;
|
return itemProvider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,14 +89,20 @@
|
||||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.newsblur.NewsBlur-Group"];
|
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.newsblur.NewsBlur-Group"];
|
||||||
NSString *host = [defaults objectForKey:@"share:host"];
|
NSString *host = [defaults objectForKey:@"share:host"];
|
||||||
NSString *token = [defaults objectForKey:@"share:token"];
|
NSString *token = [defaults objectForKey:@"share:token"];
|
||||||
|
NSString *title = self.itemTitle;
|
||||||
NSString *comments = self.contentText;
|
NSString *comments = self.contentText;
|
||||||
|
|
||||||
|
if (title && [comments isEqualToString:title]) {
|
||||||
|
comments = @"";
|
||||||
|
}
|
||||||
|
|
||||||
if (text && [comments isEqualToString:text]) {
|
if (text && [comments isEqualToString:text]) {
|
||||||
comments = @"";
|
comments = @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSCharacterSet *characterSet = [NSCharacterSet URLQueryAllowedCharacterSet];
|
NSCharacterSet *characterSet = [NSCharacterSet URLQueryAllowedCharacterSet];
|
||||||
NSString *encodedURL = url ? [url.absoluteString stringByAddingPercentEncodingWithAllowedCharacters:characterSet] : @"";
|
NSString *encodedURL = url ? [url.absoluteString stringByAddingPercentEncodingWithAllowedCharacters:characterSet] : @"";
|
||||||
|
NSString *encodedTitle = title ? [title stringByAddingPercentEncodingWithAllowedCharacters:characterSet] : @"";
|
||||||
NSString *encodedContent = text ? [text stringByAddingPercentEncodingWithAllowedCharacters:characterSet] : @"";
|
NSString *encodedContent = text ? [text stringByAddingPercentEncodingWithAllowedCharacters:characterSet] : @"";
|
||||||
NSString *encodedComments = [comments stringByAddingPercentEncodingWithAllowedCharacters:characterSet];
|
NSString *encodedComments = [comments stringByAddingPercentEncodingWithAllowedCharacters:characterSet];
|
||||||
// NSInteger time = [[NSDate date] timeIntervalSince1970];
|
// NSInteger time = [[NSDate date] timeIntervalSince1970];
|
||||||
|
@ -96,7 +112,7 @@
|
||||||
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api/share_story/%@", host, token]];
|
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api/share_story/%@", host, token]];
|
||||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL];
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL];
|
||||||
request.HTTPMethod = @"POST";
|
request.HTTPMethod = @"POST";
|
||||||
NSString *postBody = [NSString stringWithFormat:@"story_url=%@&title=&content=%@&comments=%@", encodedURL, encodedContent, encodedComments];
|
NSString *postBody = [NSString stringWithFormat:@"story_url=%@&title=%@&content=%@&comments=%@", encodedURL, encodedTitle, encodedContent, encodedComments];
|
||||||
request.HTTPBody = [postBody dataUsingEncoding:NSUTF8StringEncoding];
|
request.HTTPBody = [postBody dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
NSURLSessionTask *myTask = [mySession dataTaskWithRequest:request];
|
NSURLSessionTask *myTask = [mySession dataTaskWithRequest:request];
|
||||||
[myTask resume];
|
[myTask resume];
|
||||||
|
|
Loading…
Add table
Reference in a new issue