28 Mar 2017

ActivityController to Action & Share...


ActivityController to Action & Share...



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(120, 150, 60, 40);
    btn.backgroundColor = [UIColor redColor];
    btn.layer.borderWidth = 2;
    btn.layer.borderColor = [UIColor greenColor].CGColor;
    [btn setTitle:@"Press" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 10;
    [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

}


// ActivityController to action & Share

- (void)btnAction {

    
    NSString *string = @"Ravindar";
    NSURL *URL = [NSURL URLWithString:@"http://ravindarnalla.blogspot.in;"];
    
    UIActivityViewController *activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:@[string, URL]
                                      applicationActivities:nil];
    [self presentViewController:activityViewController animated:YES completion:nil];

  activityViewController.completionWithItemsHandler = ^(NSString *activityType,BOOL completed,NSArray *returnedItems, NSError *error){
        if (completed) {
            // user shared an item
            NSLog(@"We used activity type%@", activityType);
            
        } else {
            // user cancelled
            NSLog(@"We didn't want to share anything after all.");
        }
        if (error) {
            NSLog(@"An Error occured: %@, %@", error.localizedDescription, error.localizedFailureReason);
        }

    };
  
}



No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0