HSAttachmentPicker 1.2.0

HSAttachmentPicker 1.2.0

由以下作者维护:Jason GritmanHS BotScott PetitSam Symons



  • Help Scout

HSAttachmentPicker

CI Status Version License Platform

HSAttachmentPicker 创建了一个 UIAlertController 作为菜单,以从 iOS 上可用的相册、相机和文档浏览器 API 访问文件数据。

用法

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

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

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 文件中设置 NSPhotoLibraryUsageDescriptionNSCameraUsageDescriptionNSMicrophoneUsageDescriptionNSPhotoLibraryAddUsageDescription 属性。没有这些属性,菜单项将不可用。

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

安装

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

pod 'HSAttachmentPicker'

本地化

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

/* 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 对象上的 translationsBundletranslationTable 属性覆盖。

许可协议

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