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 / 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];
}
// 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];
- (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];
-(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);
// Get the publish permission
- (void)getPublishPermission {
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}
@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];
@SongJiaqiang
SongJiaqiang / TwitterVideoUpload.m
Created October 19, 2016 08:31
Share video to Twitter with System Social framework
#import <Foundation/Foundation.h>
#import <Social/Social.h>
#import <Accounts/Accounts.h>
typedef void(^VideoUploadCompletion)(BOOL success, NSString *errorMessage);
typedef void(^ResultAccount)(ACAccount *account);
@interface SocialVideoHelper : NSObject
+(void)getFirstTwitterAccount:(ResultAccount)complete;
@SongJiaqiang
SongJiaqiang / AuthorizationTool.h
Created November 2, 2016 04:11
iOS9 之后需要用户手动授予app权限,这段代码简化了请求权限的代码书写。暂时支持相机、相册、麦克风,其它权限以后再加。
//
// AuthorizationTool.h
// Rokk
//
// Created by Jarvis on 01/11/2016.
// Copyright © 2016 JQTech. All rights reserved.
//
#import <Foundation/Foundation.h>
- (NSString *)jsonFromDictionary:(NSDictionary *)dict {
NSDictionary *plistDict = nil;
if (dict != nil) {
plistDict = dict;
}else {
NSString *path = [[NSBundle mainBundle] pathForResource:@"items.plist" ofType:nil];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
plistDict = [NSDictionary dictionaryWithObject:array forKey:@"list"];
}
@SongJiaqiang
SongJiaqiang / DeleteFileFromDocument.m
Created November 23, 2016 01:54
delete file from document directory.
- (void)removeFile:(NSString *)filename
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:filename];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if (success) {
UIAlertView *removedSuccessFullyAlert = [[UIAlertView alloc] initWithTitle:@"Congratulations:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];