测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2017年6月 |
由Filestack iOS维护。
依赖关系 | |
Filestack | >= 0 |
GTMAppAuth | >= 0 |
GoogleAPIClientForREST | >= 0 |
GoogleAPIClientForREST/Drive | >= 0 |
GoogleAPIClientForREST/Gmail | >= 0 |
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];
// 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;
// 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;
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;
最重要的属性是 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
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"
(如图下数字所示)
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)
// 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可以使用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}];
可用的字典键(和属性)
FSStoreLocationS3
、FSStoreLocationAzure
、FSStoreLocationDropbox
、FSStoreLocationRackspace
和FSStoreLocationGoogleCloud
)。您必须在开发者门户中配置了存储才能启用此功能。一个简单的类,用于存储安全策略和签名。 FSSecurity实例是FSStoreOptions
中的security
参数。 了解更多关于安全和如何生成策略和签名的信息
- initWithPolicy:signature
FSPicker在MIT许可证下发布。请参见LICENSE以获取详细信息。