123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // ShareViewController.m
- // ShareSupport
- //
- // Created by HonorLee on 16/1/13.
- // Copyright © 2016年 HonorLee. All rights reserved.
- //
- #import "ShareViewController.h"
- #import <MobileCoreServices/MobileCoreServices.h>
- #import <libxml/HTMLparser.h>
- @interface ShareViewController ()
- @property NSUserDefaults *userDefaults;
- @property UIView *AnalyseView;
- @property NSString *SharedURL;
- @property UILabel *AnalyseViewLabel;
- @property NSString *CurrentStatus;
- @property UIActivityIndicatorView *indicator;
- @end
- @implementation ShareViewController
- - (BOOL)isContentValid {
- // Do validation of contentText and/or NSExtensionContext attachments here
- return YES;
- }
- - (void)didSelectPost {
- // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
- _userDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.honorlee.TDGroup"];
- [_userDefaults synchronize];
- NSMutableArray *tmpData = [NSMutableArray arrayWithArray:(NSMutableArray *)[_userDefaults objectForKey:@"tasks"]];
- NSLog(@"%lu",(unsigned long)[tmpData count]);
- // NSArray *inputItems = self.extensionContext.inputItems;
- // NSLog(@"%lu",(unsigned long)[inputItems count]);
- NSExtensionItem *content = self.extensionContext.inputItems[0];
- NSItemProvider *itemProvider = content.attachments.firstObject;
- if([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
- [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url,NSError *err) {
- NSString *sharedURL = url.absoluteString;
- if([sharedURL containsString:@"tumblr.com"]){
- [tmpData addObject:sharedURL];
- [_userDefaults setObject:tmpData forKey:@"tasks"];
- [_userDefaults synchronize];
- }else{
- NSLog(@"Not tumblr");
- }
- }];
- }
-
-
- // NSString *type = (NSString *)
- // 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.
-
- }
- -(void)viewDidLoad{
- UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- [backgroundView setBackgroundColor:[UIColor blackColor]];
- [backgroundView setAlpha:0.6];
- [self.view sendSubviewToBack:backgroundView];
- [self.view addSubview:backgroundView];
- [self.view bringSubviewToFront:_FirstView];
- _FirstView.layer.cornerRadius = 5;
- _FirstView.layer.masksToBounds = YES;
- NSExtensionItem *content = self.extensionContext.inputItems[0];
- NSItemProvider *itemProvider = content.attachments.firstObject;
- if([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]){
- [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url,NSError *err) {
- _SharedURL = url.absoluteString;
- dispatch_async(dispatch_get_main_queue(), ^{
- [_FistViewURLText setText:_SharedURL];
- });
- if(![_SharedURL containsString:@"tumblr.com"]){
- //[_FirstNextBtn setEnabled:NO];
- }
- }];
- }
- }
- - (NSArray *)configurationItems {
- // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
- return @[];
- }
- // Cancel
- - (IBAction)Cancel:(id)sender {
- [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
- }
- - (IBAction)Analyse:(id)sender {
- _AnalyseView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-300)/2, (self.view.frame.size.height-140)/2, 300, 140)];
- [_AnalyseView setBackgroundColor:[UIColor whiteColor]];
- [_AnalyseView.layer setCornerRadius:5];
- [_AnalyseView.layer setMasksToBounds:YES];
- _indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
- [self.view addSubview:_AnalyseView];
- [_AnalyseView addSubview:_indicator];
- [_indicator startAnimating];
- [UIView transitionFromView:_FirstView toView:_AnalyseView duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
- [_FirstView removeFromSuperview];
- }];
- }
- #pragma AnalyseURL
- -(void)ChangeStatus{
-
- }
- @end
|