AttachmentPicker 1.0.10

AttachmentPicker 1.0.10

Scott PetitHS BotSam Symons 维护。



  • Help Scout

HSAttachmentPicker

CI Status Version License Platform

HSAttachmentPicker 创建了一个 UIAlertController 作为菜单,用于在 iOS 上通过照片、相机和文档浏览器 API 访问文件数据。

使用方法

要使用附件选择器,请创建一个新的 HSAttachmentPicker 实例,指派一个代理,并调用 showAttachmentMenu

Objective-C

您可以在 示例项目 中找到使用附件选择器的完整示例。

HSAttachmentPicker *menu = [[HSAttachmentPicker alloc] init];
menu.delegate = self;
[menu showAttachmentMenu];

Swift

class ViewController: UIViewController {
  let picker = HSAttachmentPicker()

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    picker.delegate = self
    picker.showAttachmentMenu()
  }
}

extension ViewController: HSAttachmentPickerDelegate {
  func attachmentPickerMenu(_ menu: HSAttachmentPicker, showErrorMessage errorMessage: String) {
    // Handle errors
  }

  func attachmentPickerMenuDismissed(_ menu: HSAttachmentPicker) {
    // Run some code when the picker is dismissed
  }

  func attachmentPickerMenu(_ menu: HSAttachmentPicker, show controller: UIViewController, completion: (() -> Void)? = nil) {
    self.present(controller, animated: true, completion: completion)
  }

  func attachmentPickerMenu(_ menu: HSAttachmentPicker, upload data: Data, filename: String, image: UIImage?) {
    // Do something with the data of the selected attachment, i.e. upload it to a web service
  }
}

示例

要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install

示例项目仅包含一个简单的代理,用于演示目的并记录操作。

需求

为了使用图片和相机功能,需要在您的应用的 Info.plist 文件中设置 NSPhotoLibraryUsageDescriptionNSCameraUsageDescription 属性。如果没有这些属性,菜单项将不可用。

要访问文档选择器,需要具有 iCloud 和 iCloud 容器的权限。否则,您会在“从文件导入”菜单选项上通过代理抛出错误消息。

安装

HSAttachmentPicker 通过 CocoaPods 提供。要安装它,请简单地将以下行添加到您的 Podfile 中

pod 'AttachmentPicker'

本地化

以下字符串可以指定以覆盖默认消息

/* Menu Items */

"Take Photo"="Take Photo";

"Use Last Photo"="Use Last Photo";

"Choose from Library"="Choose from Library";

"Import File from"="Import File from";

"Cancel"="Cancel";

"OK"="OK";

/* Errors */

"This application is not entitled to access iCloud"="This application is not entitled to access iCloud";

"There doesn't seem to be a photo taken yet."="There doesn't seem to be a photo taken yet.";

"To give permissions tap on 'Change Settings' button"="To give permissions tap on 'Change Settings' button";

"Unable to save video: %@"="Unable to save video: %@";

"Unable to save photo: %@"="Unable to save photo: %@";

"Selected media type is unsupported"="Selected media type is unsupported";

/* Preview */

"Preview": "Preview";

"Use": "Use";

默认情况下,它将检查 NSBundle.mainBundleLocalizable.strings,但这些值可以使用 HSAttachmentPicker 对象上的 translationsBundletranslationsTable 属性来覆盖。

许可证

HSAttachmentPicker 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。