Last active
October 8, 2017 23:43
-
-
Save sportnak/93f4909ac1adbcae98219108141bfb98 to your computer and use it in GitHub Desktop.
Context acquisition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)loadView { | |
[super loadView]; | |
//this is to retrieve from the app group | |
NSUserDefaults *bucket = [[NSUserDefaults alloc] initWithSuiteName:appGroupName]; | |
// assign your member values | |
[self loadContext]; | |
} | |
- (void)loadContext | |
{ | |
NSExtensionContext *context = self.extensionContext; | |
NSExtensionItem *item = [context.inputItems firstObject]; | |
m_contextText = self.contentText; | |
@try | |
{ | |
NSArray *attachments = item.attachments; | |
[attachments enumerateObjectsUsingBlock:^(NSItemProvider *provider, NSUInteger idx, BOOL *stop) | |
{ | |
if ([provider hasItemConformingToTypeIdentifier:URL_IDENTIFIER]) | |
{ | |
[provider | |
loadItemForTypeIdentifier:URL_IDENTIFIER | |
options:nil | |
completionHandler: ^(NSURL *item, NSError *error) { | |
m_contextUrl = item; | |
}]; | |
} | |
else if ([provider hasItemConformingToTypeIdentifier:IMAGE_IDENTIFIER]) | |
{ | |
[provider | |
loadItemForTypeIdentifier:IMAGE_IDENTIFIER | |
options:nil | |
completionHandler: ^(id<NSSecureCoding> item, NSError *error) { | |
NSData *imgData; | |
if([(NSObject*)item isKindOfClass:[NSURL class]]) | |
imgData = [NSData dataWithContentsOfURL:(NSURL*)item]; | |
if([(NSObject*)item isKindOfClass:[UIImage class]]) | |
imgData = UIImagePNGRepresentation((UIImage*)item); | |
[m_contextImgData addObject:imgData]; | |
}]; | |
} | |
else if ([provider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePlainText]) | |
{ | |
[provider | |
loadItemForTypeIdentifier:(NSString *)kUTTypePlainText | |
options:nil | |
completionHandler: ^(id<NSSecureCoding> item, NSError *error) { | |
m_contextText = (NSString *)item; | |
}]; | |
} | |
} | |
]; | |
} | |
@catch (NSException *exception) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment