FSPicker 1.1.8

FSPicker 1.1.8

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2017年6月

Filestack iOS维护。



 
依赖关系
Filestack>= 0
GTMAppAuth>= 0
GoogleAPIClientForREST>= 0
GoogleAPIClientForREST/Drive>= 0
GoogleAPIClientForREST/Gmail>= 0
 

FSPicker 1.1.8

  • Filestack

FSPicker for iOS

FSPicker 是 Filestack 重新实现的 iOS-picker。如果您有任何功能请求或错误报告,请打开一个问题或 PR。

要求

iOS 8.4 或更高版本

文档

基本初始化

要开始使用 FSPicker,您需要导入模块

#import <FSPicker/FSPicker.h>
// or
@import FSPicker;

要集成 Google 服务和 Google 登录,请阅读 GoogleServicesIntegration

初始化 config(可选 theme存储选项),最后初始化 FSPickerController

FSConfig *config = [[FSConfig alloc] initWithApiKey:@"YOUR_API_KEY"];

FSStoreOptions *storeOptions = [[FSStoreOptions alloc] init];
storeOptions.location = FSStoreLocationS3;

config.storeOptions = storeOptions;

FSTheme *theme = [FSTheme filestackTheme];

FSPickerController *fsPickerController = [[FSPickerController alloc] initWithConfig:config theme:theme];
fsPickerController.fsDelegate = self;

// present the controller
[self presentViewController:fsPickerController animated:YES completion:nil];

// Or for FSSaveController

// configure the data
NSString *testImagePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
NSURL *testImageURL = [NSURL URLWithString:testImagePath];

config.dataMimeType = FSMimeTypeImagePNG;
config.localDataURL = testImageURL;
config.proposedFileName = @"newimage";

// present the controller
FSSaveController *fsSaveController = [[FSSaveController alloc] initWithConfig:config theme:theme];
fsSaveController.fsDelegate = self;
[self presentViewController:fsSaveController animated:YES completion:nil];

FSPickerDelegate

// Called when user dismisses the picker controller.
- (void)fsPickerDidCancel:(FSPickerController *)picker;

// Called when picking of a single file resulted in error.
// This does not mean that picking of the rest of the files (in case of multiple files available) is interrupted.
// All files of multiple files pick, that resulted in error will call this method.
- (void)fsPicker:(FSPickerController *)picker pickingDidError:(NSError *)error;

// Called when picking of a single file completed with success.
// If you are picking multiple files this will be called for each of successfully picked file.
- (void)fsPicker:(FSPickerController *)picker pickedMediaWithBlob:(FSBlob *)blob;

// Called when "files picking" is finished. Blobs array will contain blobs of all successfully picked files.
- (void)fsPicker:(FSPickerController *)picker didFinishPickingMediaWithBlobs:(NSArray<FSBlob *> *)blobs;

FSSaveDelegate

// Called when user dismisses the save controller.
- (void)fsSaveControllerDidCancel:(FSSaveController *)saveController;

// Called when saving of data resulted in error.
- (void)fsSaveController:(FSSaveController *)saveController savingDidError:(NSError *)error;

// Called when saving of data completed with success.
- (void)fsSaveController:(FSSaveController *)saveController didFinishSavingMediaWithBlob:(FSBlob *)blob;

FSConfig

可用的属性

NSString *apiKey;
NSString *title;
NSArray<NSString *> *sources;

// FSPickerController
NSArray<FSMimeType> *mimeTypes;
NSInteger maxFiles;
NSUInteger maxSize;
BOOL selectMultiple;
BOOL defaultToFrontCamera;
BOOL shouldDownload;
// BOOL shouldUpload; TODO
FSStoreOptions *storeOptions;

// FSSaveController
NSData *data;
NSURL *localDataURL;
FSMimeType dataMimeType;
NSString *dataExtension;
NSString *proposedFileName;

"配置 config"

最重要的属性是 apiKey,这也是您需要提供给 FSPicker 的唯一属性。您可以在开发者门户中找到您应用程序的 API 密钥。

title 设置 FSPickerController/FSSaveController 的导航栏标题。默认为 "Filestack"。

sources 数组允许您配置您希望在应用程序中可用的来源。您可以在下面找到来源名称 常量。如果未设置或为空数组,则将显示列表中的所有来源。

mimeTypes 数组用于限制显示的文件类型。定义了方便的 typedef。如果未提供此属性,则所有文件类型都可用于上传 (/)。

selectMultiple 默认为 YES。如果设置为 NO,则在选择时 FSPicker 将自动“选择”文件。

defaultToFrontCamera - 如果您希望以前置摄像头作为默认方式打开“相册”源,请将其设置为YES。

maxFiles 设置同时上传的最大文件数。默认为无限。

maxSize 限制上传文件大小不超过maxSize字节,默认文件大小不受限制。如果指定了,则大于maxSize的文件不会显示在PickerController中。

shouldDownload 使用PickerController选择文件后,文件会被下载到设备的临时存储中。路径在FSBlob的internalURL属性中可用。

shouldUpload #TODO

storeOptions FSStoreOptions

data 要导出的数据。您必须设置此属性或localDataURL属性,以便能够使用FSSaveController。

localDataURL 本地数据的URL。您必须设置此属性或data属性,以便能够使用FSSaveController。

dataMimeType 您希望导出的数据的MIME类型。此设置不是必需的,但强烈推荐提供它或提供dataExtension

dataExtension 您希望导出的数据的扩展名。您可以与dataMimeType互用。

proposedFileName 将设置在“文件名字段”中的文件名。这不包含扩展名。如果没有提供名称,最终用户将被要求提供。

源名称常量

FSSourceBox
FSSourceCameraRoll
FSSourceDropbox
FSSourceFacebook
FSSourceGithub
FSSourceGmail
FSSourceImageSearch
FSSourceCamera
FSSourceGoogleDrive
FSSourceInstagram
FSSourceFlickr
FSSourcePicasa
FSSourceSkydrive
FSSourceEvernote
FSSourceCloudDrive

MIME类型typedef

typedef NSString * FSMimeType;

FSMimeTypeAll @"*/*"

FSMimeTypeAudioAll @"audio/*"

FSMimeTypeVideoAll @"video/*"
FSMimeTypeVideoQuickTime @"video/quicktime"

FSMimeTypeImageAll @"image/*"
FSMimeTypeImagePNG @"image/png"
FSMimeTypeImageJPEG @"image/jpeg"
FSMimeTypeImageBMP @"image/bmp"
FSMimeTypeImageGIF @"image/gif"
FSMimeTypeImageSVG @"image/svg+xml"
FSMimeTypeImageTIFF @"image/tiff"
FSMimeTypeImagePSD @"image/vnd.adobe.photoshop"

FSMimeTypeApplicationAll @"application/*"
FSMimeTypeApplicationPDF @"application/pdf"
FSMimeTypeApplicationDOC @"application/msword"
FSMimeTypeApplicationDOCX @"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
FSMimeTypeApplicationODT @"application/vnd.oasis.opendocument.text"
FSMimeTypeApplicationXLS @"application/vnd.ms-excel"
FSMimeTypeApplicationXLSX @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
FSMimeTypeApplicationODS @"application/vnd.oasis.opendocument.spreadsheet"
FSMimeTypeApplicationPPT @"application/vnd.ms-powerpoint"
FSMimeTypeApplicationPPTX @"application/vnd.openxmlformats-officedocument.presentationml.presentation"
FSMimeTypeApplicationODP @"application/vnd.oasis.opendocument.presentation"
FSMimeTypeApplicationAI @"application/illustrator"
FSMimeTypeApplicationJSON @"application/json"

FSMimeTypeTextAll @"text/*"
FSMimeTypeTextHTML @"text/html"
FSMimeTypeTextPlain @"text/plain; charset=UTF-8"

FSTheme

可用属性

(如图下数字所示)

UIBarStyle navigationBarStyle
NSAttributedString *refreshControlAttributedTitle (11)
UIColor *navigationBarBackgroundColor (6)
UIColor *navigationBarTintColor (1)
UIColor *navigationBarTitleColor
UIColor *headerFooterViewTintColor (2)
UIColor *headerFooterViewTextColor (3)
UIColor *tableViewBackgroundColor
UIColor *tableViewSeparatorColor (5)
UIColor *tableViewCellBackgroundColor (13b)
UIColor *tableViewCellTextColor (13c)
UIColor *cellIconTintColor (4, 17)
UIColor *tableViewCellIconTintColor (4)
UIColor *tableViewCellSelectedBackgroundColor (13)
UIColor *tableViewCellSelectedTextColor (13a)
UIColor *tableViewCellImageViewBorderColor (14)
UIColor *collectionViewBackgroundColor
UIColor *collectionViewCellBackgroundColor
UIColor *collectionViewCellBorderColor (15)
UIColor *collectionViewCellTitleTextColor (16)
UIColor *uploadButtonTextColor (10)
UIColor *uploadButtonBackgroundColor (9)
UIColor *refreshControlTintColor (12)
UIColor *refreshControlBackgroundColor (12a)
UIColor *searchBarBackgroundColor (19)
UIColor *searchBarTintColor (18)
UIColor *activityIndicatorColor
UIColor *progressCircleTrackColor (7)
UIColor *progressCircleProgressColor (8)

Fig1 Fig2 Fig3 Fig4 Fig5 Fig6 Fig7

// Example
FSTheme *theme = [[FSTheme alloc] init];
theme.uploadButtonTextColor = [UIColor redColor];
theme.progressCircleTrackColor = [UIColor blueColor];
theme.progressCircleProgressColor = [UIColor whiteColor];

NSDictionary *attributes = @{NSForegroundColorAttributeName: [UIColor blackColor]};
theme.refreshControlAttributedTitle = [[NSAttributedString alloc] initWithString:@"Loading stuff" attributes:attributes];

FSStoreOptions

一个便利类,用于创建一个可选对象以配置如何存储数据。FSStoreOptions可以使用NSDictionary或默认情况下使用[[FSStoreOptions alloc] init]进行初始化,然后“手动”设置值。

// Example
FSStoreOptions *options = [[FSStoreOptions alloc] init];
options.location = FSStoreLocationS3;

// "fileName" and "mimeType" properties are omitted while uploading files using FSPicker.

// Example
FSStoreOptions *options = [[FSStoreOptions alloc] initWithDictionary:@{@"location": FSStoreLocationS3}];

可用的字典键(和属性)

  • location (NSString的FSStoreLocation typedef,FSStoreLocationAzure,FSStoreLocationDropbox,FSStoreLocationRackspace或FSStoreLocationGoogleCloud)
    • 存储文件的位置。《如果未提供位置,FSPicker将使用“pick”方法创建对您的文件的符号链接,或者文件(本地)将存储在Filestack的S3上。《其他选项为's3'、'azure'、'dropbox'、'rackspace'和'gcs'(FSStoreLocationS3FSStoreLocationAzureFSStoreLocationDropboxFSStoreLocationRackspaceFSStoreLocationGoogleCloud)。您必须在开发者门户中配置了存储才能启用此功能。
  • path (NSString)
    • 在指定的文件存储位置中存储文件的路劲。对于S3,这是文件将被存储的位置的键。默认情况下,Filestack将文件存储在根目录中,使用唯一的ID,后面跟一个下划线,然后是文件名,例如“3AB239102DB_myphoto.png”。如果提供的路径以'/'结尾,则它被视为文件夹,因此如果提供的路径为“myfiles/”并且上传的文件被命名为“myphoto.png”,则文件将被存储在“myfiles/909DFAC9CB12_myphoto.png”。
  • container (NSString)
    • 指定文件存储中文件最终应放置的存储桶或容器。这在您有不同的测试和生产容器并且想同时在同一个Filestack应用程序中使用它们时非常有用。如果省略此参数,文件将存储在开发门户网站中指定的默认容器中。请注意,此参数不适用于Dropbox文件存储。
  • access (NSString类型FSAccess的FSAccess typedef,可以是FSAccessPublic或FSAccessPrivate)
    • 指示文件应按允许直接访问底层文件存储的方式进行存储。例如,如果文件存储在S3上,这将允许直接使用S3 URL。这不会影响用户读取Filestack文件URL的能力。默认为'private'。
  • base64decode (BOOL)
    • 指定您希望在将数据写入文件之前首先从base64解码。例如,如果您有base64编码的图像数据,您可以使用此标志首先解码数据然后在写入图像文件。
  • security (FSSecurity)

FSSecurity类

一个简单的类,用于存储安全策略和签名。 FSSecurity实例是FSStoreOptions中的security参数。 了解更多关于安全和如何生成策略和签名的信息

- initWithPolicy:signature

许可证

FSPicker在MIT许可证下发布。请参见LICENSE以获取详细信息。