Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to share video in iOS #1124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<source-file src="src/ios/NSString+SSURLEncoding.m"/>
<header-file src="src/ios/SocialSharing.h"/>
<source-file src="src/ios/SocialSharing.m"/>
<header-file src="src/ios/ShareContent.h"/>
<source-file src="src/ios/ShareContent.m"/>
<header-file src="src/ios/CustomSLComposeViewController.h"/>
<source-file src="src/ios/CustomSLComposeViewController.m"/>

<framework src="Social.framework" weak="true" />
<framework src="MessageUI.framework" weak="true" />
Expand Down
10 changes: 10 additions & 0 deletions src/ios/CustomSLComposeViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <Foundation/NSURL.h>
#import <Social/Social.h>
#import <MobileCoreServices/MobileCoreServices.h>

@interface CustomSLComposeViewController:SLComposeViewController

- (BOOL)addVideoURL:(NSURL *)url;

@end

22 changes: 22 additions & 0 deletions src/ios/CustomSLComposeViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#import "CustomSLComposeViewController.h"
#import <Foundation/NSURL.h>
#import <Social/Social.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <UIKit/UIKit.h>

// This class extends SLComposeViewController and adds ability of share videos
@implementation CustomSLComposeViewController

- (BOOL)addVideoURL:(NSURL *)url {
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithItem:url typeIdentifier:(NSString *)kUTTypeMPEG4];

NSExtensionItem *extensionItem = [NSExtensionItem new];
extensionItem.attachments = [NSArray arrayWithObject:itemProvider];

return [self performSelector:@selector(addExtensionItem:) withObject:extensionItem];
}

+ (CustomSLComposeViewController *)composeViewControllerForServiceType:(NSString *)serviceType{
return (CustomSLComposeViewController *)[super composeViewControllerForServiceType:serviceType];
}
@end
16 changes: 16 additions & 0 deletions src/ios/ShareContent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import <Foundation/NSURL.h>
#import <MobileCoreServices/MobileCoreServices.h>

typedef NS_ENUM(NSUInteger, ContentType) {
IMAGE,
VIDEO,
AUDIO,
OTHER
};

@interface ShareContent : NSObject
- (ContentType)getType;
- (void)setUrl:(NSURL *)url;
- (NSURL*)getUrl;
@end

37 changes: 37 additions & 0 deletions src/ios/ShareContent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#import "ShareContent.h"
#import <Foundation/NSURL.h>
#import <MobileCoreServices/MobileCoreServices.h>

@implementation ShareContent {
NSURL * _url;
ContentType _type;
}

- (ContentType)getType {
return _type;
};

- (void)setUrl:(NSURL *)url {
_url = url;
if (_url == nil)
return;
CFStringRef fileExtension = (__bridge CFStringRef) [url pathExtension];
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
CFRelease(UTI);
NSString *type = (__bridge_transfer NSString *) MIMEType;
if ([type hasPrefix:@"image"])
_type = IMAGE;
else if ([type hasPrefix:@"video"])
_type = VIDEO;
else if ([type hasPrefix:@"audio"])
_type = AUDIO;
else
_type = OTHER;
}

- (NSURL *)getUrl {
return _url;
};

@end
Loading