Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save and Share Image and Video 因为用掉了相册(写)权限
//Share Image or Video
- (void)shareToFriends:(UIImage *)image videoPath:(NSString *)path
{
[GZToast hideToast];
NSArray *objectsToShare;
if (image) {
objectsToShare = @[image];
}else if(path){
NSURL*urlToShare= [NSURL fileURLWithPath:path];
objectsToShare = @[urlToShare];
} else {
[GZToast showToast:@"Export Video Fail!" toastType:GZToastTypeError];
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = @[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityVC animated:YES completion:nil];
}
else {
UIPopoverPresentationController *presentVC = activityVC.popoverPresentationController;
presentVC.sourceView = self.view;
presentVC.sourceRect = CGRectMake(S_X(187.5), S_Y(500), 0, 0);
presentVC.permittedArrowDirections = UIPopoverArrowDirectionDown;
[self presentViewController:activityVC animated:YES completion:nil];
}
}
//Save Video
- (void)saveVideoToCameraRoall:(NSString *)videoPath
{
if (videoPath) {
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath)) {
UISaveVideoAtPathToSavedPhotosAlbum(videoPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
}
}
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
{
if (error) {
NSLog(@"videoPath = %@, error = %@, contextInfo = %@", videoPath, error, contextInfo);
[GZToast showToast:@"Saved failed" toastType:GZToastTypeError];
}else{
[GZToast showToast:@"Saved" toastType:GZToastTypeSuccess];
}
}
//Save Image
- (void)saveImageToCameraRoall:(UIImage *)image {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error) {
NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
[GZToast showToast:@"Saved failed" toastType:GZToastTypeError];
}else{
NSLog(@"Save successfully");
[GZToast showToast:@"Saved" toastType:GZToastTypeSuccess];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.