ShareViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #import <libxml/HTMLparser.h>
  11. @interface ShareViewController ()
  12. @property NSUserDefaults *userDefaults;
  13. @property UIView *AnalyseView;
  14. @property NSString *SharedURL;
  15. @property UILabel *AnalyseViewLabel;
  16. @property NSString *CurrentStatus;
  17. @property UIActivityIndicatorView *indicator;
  18. @end
  19. @implementation ShareViewController
  20. - (BOOL)isContentValid {
  21. // Do validation of contentText and/or NSExtensionContext attachments here
  22. return YES;
  23. }
  24. - (void)didSelectPost {
  25. // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
  26. _userDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.honorlee.TDGroup"];
  27. [_userDefaults synchronize];
  28. NSMutableArray *tmpData = [NSMutableArray arrayWithArray:(NSMutableArray *)[_userDefaults objectForKey:@"tasks"]];
  29. NSLog(@"%lu",(unsigned long)[tmpData count]);
  30. // NSArray *inputItems = self.extensionContext.inputItems;
  31. // NSLog(@"%lu",(unsigned long)[inputItems count]);
  32. NSExtensionItem *content = self.extensionContext.inputItems[0];
  33. NSItemProvider *itemProvider = content.attachments.firstObject;
  34. if([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
  35. [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url,NSError *err) {
  36. NSString *sharedURL = url.absoluteString;
  37. if([sharedURL containsString:@"tumblr.com"]){
  38. [tmpData addObject:sharedURL];
  39. [_userDefaults setObject:tmpData forKey:@"tasks"];
  40. [_userDefaults synchronize];
  41. }else{
  42. NSLog(@"Not tumblr");
  43. }
  44. }];
  45. }
  46. // NSString *type = (NSString *)
  47. // 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.
  48. }
  49. -(void)viewDidLoad{
  50. UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
  51. [backgroundView setBackgroundColor:[UIColor blackColor]];
  52. [backgroundView setAlpha:0.6];
  53. [self.view sendSubviewToBack:backgroundView];
  54. [self.view addSubview:backgroundView];
  55. [self.view bringSubviewToFront:_FirstView];
  56. _FirstView.layer.cornerRadius = 5;
  57. _FirstView.layer.masksToBounds = YES;
  58. NSExtensionItem *content = self.extensionContext.inputItems[0];
  59. NSItemProvider *itemProvider = content.attachments.firstObject;
  60. if([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
  61. [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url,NSError *err) {
  62. _SharedURL = url.absoluteString;
  63. dispatch_async(dispatch_get_main_queue(), ^{
  64. [_FistViewURLText setText:_SharedURL];
  65. });
  66. if(![_SharedURL containsString:@"tumblr.com"]){
  67. //[_FirstNextBtn setEnabled:NO];
  68. }
  69. }];
  70. }
  71. }
  72. - (NSArray *)configurationItems {
  73. // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
  74. return @[];
  75. }
  76. // Cancel
  77. - (IBAction)Cancel:(id)sender {
  78. [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
  79. }
  80. - (IBAction)Analyse:(id)sender {
  81. _AnalyseView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-300)/2, (self.view.frame.size.height-140)/2, 300, 140)];
  82. [_AnalyseView setBackgroundColor:[UIColor whiteColor]];
  83. [_AnalyseView.layer setCornerRadius:5];
  84. [_AnalyseView.layer setMasksToBounds:YES];
  85. _indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
  86. [self.view addSubview:_AnalyseView];
  87. [_AnalyseView addSubview:_indicator];
  88. [_indicator startAnimating];
  89. [UIView transitionFromView:_FirstView toView:_AnalyseView duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
  90. [_FirstView removeFromSuperview];
  91. }];
  92. }
  93. #pragma AnalyseURL
  94. -(void)ChangeStatus{
  95. }
  96. @end