Default Sharing in iOS 7

前端 未结 6 1182
悲哀的现实
悲哀的现实 2020-12-23 11:23

I have seen this format (Image shown below) of share option in most of the iOS applications that support iOS 7. Is there a default code/framework available to implement this

6条回答
  •  余生分开走
    2020-12-23 12:08

    In addition to the accepted answer, a small piece of example code

    - (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url
        {
            NSMutableArray *sharingItems = [NSMutableArray new];
            if (text) {
                [sharingItems addObject:text];
            }
            if (image) {
                [sharingItems addObject:image];
            }
            if (url) {
                [sharingItems addObject:url];
            }
            UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
            [self presentViewController:activityController animated:YES completion:nil];
        }
    

    Call shareText, leave the things that you don't want to share at nil.

    [self shareText:@"Hello world" andImage:nil andUrl:nil];
    

提交回复
热议问题