ShareViewController.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // ShareViewController.m
  3. // ShareSupport
  4. //
  5. // Created by HonorLee on 16/1/13.
  6. // Copyright © 2016年 HonorLee. All rights reserved.
  7. //
  8. #import "ShareViewController.h"
  9. #import <MobileCoreServices/MobileCoreServices.h>
  10. @interface ShareViewController ()
  11. @property NSUserDefaults *userDefaults;
  12. @end
  13. @implementation ShareViewController
  14. - (BOOL)isContentValid {
  15. // Do validation of contentText and/or NSExtensionContext attachments here
  16. return YES;
  17. }
  18. - (void)didSelectPost {
  19. // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
  20. _userDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.honorlee.TumblrDownloader"];
  21. [_userDefaults synchronize];
  22. NSMutableArray *tmpData = [NSMutableArray arrayWithArray:(NSMutableArray *)[_userDefaults objectForKey:@"tasks"]];
  23. NSLog(@"%lu",(unsigned long)[tmpData count]);
  24. // NSArray *inputItems = self.extensionContext.inputItems;
  25. // NSLog(@"%lu",(unsigned long)[inputItems count]);
  26. NSExtensionItem *content = self.extensionContext.inputItems[0];
  27. NSItemProvider *itemProvider = content.attachments.firstObject;
  28. if([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
  29. [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url,NSError *err) {
  30. [tmpData addObject:url.absoluteString];
  31. [_userDefaults setObject:tmpData forKey:@"tasks"];
  32. [_userDefaults synchronize];
  33. }];
  34. }
  35. [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
  36. // NSString *type = (NSString *)
  37. // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
  38. }
  39. - (NSArray *)configurationItems {
  40. // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
  41. return @[];
  42. }
  43. @end