NewsBlur/clients/ios/Classes/StoryTitleAttributedString.m
Nicholas Riley dc6742b8c0 Improve story drag and drop on iPad.
Provide (in descending priority order):

1. an StoryTitleAttributedString object which provides attributed string containing the (optional) image and a link, for drops into apps such as Notes, or if rich text is unsupported, Story Title <story URL>.

2. a URL (alone)

This avoids the issue where a “2” or “3” is displayed and multiple items appear to be being dragged (see #1072).

Correctly return an empty array rather than nil if we have nothing to drag.
2018-01-06 13:35:20 -05:00

37 lines
1.2 KiB
Objective-C

//
// StoryTitleAttributedString.m
// NewsBlur
//
// Created by Nicholas Riley on 1/6/2018.
// Copyright © 2018 NewsBlur. All rights reserved.
//
#import "StoryTitleAttributedString.h"
@implementation StoryTitleAttributedString
- (instancetype)initWithAttributedString:(NSAttributedString *)attrStr plainString:(NSString *)plainStr {
if ( (self = [self init]) != nil) {
attributedString = attrStr;
plainString = plainStr;
}
return self;
}
+ (NSArray<NSString *> *)writableTypeIdentifiersForItemProvider {
return NSAttributedString.writableTypeIdentifiersForItemProvider;
}
#pragma mark - NSItemProviderWriting
- (nullable NSProgress *)loadDataWithTypeIdentifier:(nonnull NSString *)typeIdentifier forItemProviderCompletionHandler:(nonnull void (^)(NSData * _Nullable, NSError * _Nullable))completionHandler {
NSLog(@"requested: %@", typeIdentifier);
if ([typeIdentifier isEqualToString:(NSString *)kUTTypeUTF8PlainText])
return [plainString loadDataWithTypeIdentifier:typeIdentifier forItemProviderCompletionHandler:completionHandler];
return [attributedString loadDataWithTypeIdentifier:typeIdentifier forItemProviderCompletionHandler:completionHandler];
}
@end