-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathShareViewController.m
61 lines (47 loc) · 2.03 KB
/
ShareViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import "ShareViewController.h"
#import <XExtensionItem/XExtensionItem.h>
#import <XExtensionItem/XExtensionItemTumblrParameters.h>
@implementation ShareViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
for (NSExtensionItem *extensionItem in self.extensionContext.inputItems) {
/*
Loop through the incoming `NSExtensionItem` instances and create an `XExtensionItem` instance out of each.
*/
XExtensionItem *xExtensionItem = [[XExtensionItem alloc] initWithExtensionItem:extensionItem];
NSLog(@"XExtensionItem: %@", xExtensionItem);
/*
Look through each extension item’s attachments array and load each attachments’ items.
*/
for (NSItemProvider *itemProvider in xExtensionItem.attachments) {
for (NSString *typeIdentifier in itemProvider.registeredTypeIdentifiers) {
[itemProvider loadItemForTypeIdentifier:typeIdentifier options:nil completionHandler:^(id <NSSecureCoding> attachmentItem, NSError *error) {
NSLog(@"Attachment item: %@", attachmentItem);
}];
}
}
/*
Pull out some generic parameters.
*/
NSLog(@"Tags: %@", xExtensionItem.tags);
NSLog(@"Referrer: %@", xExtensionItem.referrer);
/*
Pull out custom parameter values by initializing a custom parameter class with the extension item’s `userInfo`
dictionary.
*/
XExtensionItemTumblrParameters *tumblrParameters = [[XExtensionItemTumblrParameters alloc] initWithDictionary:xExtensionItem.userInfo];
NSLog(@"Tumblr custom URL path component: %@", tumblrParameters.customURLPathComponent);
}
}
#pragma mark - SLComposeServiceViewController
- (BOOL)isContentValid {
return YES;
}
- (void)didSelectPost {
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
}
- (NSArray *)configurationItems {
return @[];
}
@end