Skip to content

Instantly share code, notes, and snippets.

View SongJiaqiang's full-sized avatar
🌴
On vacation

Jarvis SongJiaqiang

🌴
On vacation
View GitHub Profile
@SongJiaqiang
SongJiaqiang / ShareTool.m
Last active October 19, 2016 06:38
Share video to facebook with FB SDK v4.16
@implementation ShareTool
+ (void)shareVideoToFacebookWithVideoURL:(NSURL *)videoAssetLibraryURL fromViewController:(UIViewController *)viewController {
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
[ShareTool showAlertDialogWithTitle:@"NOTICE" andMessage:@"You Did Not Install Facebook" fromViewController:viewController];
break;
}
FBSDKShareVideo *fbVideo = [[FBSDKShareVideo alloc] init];
FBSDKShareVideoContent *fbVideoContent = [[FBSDKShareVideoContent alloc] init];
// Get the publish permission
- (void)getPublishPermission {
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}
-(void)shareOnFaceBook
{
//sample_video.mov is the name of file
NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:@"sample_video" ofType:@"mov"];
NSLog(@"Path Of Video is %@", filePathOfVideo);
NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
//you can use dataWithContentsOfURL if you have a Url of video file
//NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
//NSLog(@"data is :%@",videoData);
- (void)facebookLogin {
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
[self shareVideoOnFacebook];
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut]; //very important line for login to work
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if(!error) {
[self shareVideoOnFacebook];
// import them, FacebookSDK.framework, FBSDKLoginKit.framework, FBSDKShareKit.framework, Bolts.framework,FBSDKCoreKit.framework
- (void)shareVideoToFacebook {
if(![FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login1 = [[FBSDKLoginManager alloc]init];
[login1 logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoAssetURL;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video;
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];
@SongJiaqiang
SongJiaqiang / PickVideoFromAlbum.m
Last active July 20, 2018 04:09
从相册选取视频
- (void)pickVideoFromAlbum {
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
videoPicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];‌​
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:videoPicker animated:YES completion:nil];
}