前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >提交 BookReader Framework 到 CocoaPodsBookReaderCocoaPods

提交 BookReader Framework 到 CocoaPodsBookReaderCocoaPods

作者头像
iOSDevLog
发布2018-07-25 16:58:22
5040
发布2018-07-25 16:58:22
举报
文章被收录于专栏:iOSDevLogiOSDevLog

iOS 11 支持 pdf 查看。

在 GitHub 上面找到一个比较好的示例,可惜没有做成动态库,那就我来做好了。

https://github.com/kishikawakatsumi/BookReader

BookReader

Sample code for PDFKit on iOS 11, clone of iBooks.app built on top of PDFKit.

BookReader

CocoaPods


https://guides.cocoapods.org/making/using-pod-lib-create.html

注册 pod trunk register

代码语言:javascript
复制
$ pod trunk register iosdevlog@iosdevlog.com 'iosdevlog' --description='iMac'
[!] Please verify the session by clicking the link in the verification email that has been sent to iosdevlog@iosdevlog.com
$ pod trunk me
  - Name:     iosdevlog
  - Email:    iosdevlog@iosdevlog.com
代码语言:javascript
复制
$ pod lib create BookReader

一路 enter,测试库什么的先放上,以后有时间一再加测试用例上去。

新建一个空的 GitHub 地址https://github.com/iOSDevLog/BookReader

swift 代码放入 BookReader/BookReader/Classes/ 目录下,资源文件 *.png*.xib*.storyboard 放入 BookReader/BookReader/Assets/

ios.deployment_target 改成 iOS 11 ,再加入 PDFKit。添加 swift 版本信息。

代码语言:javascript
复制
#
# Be sure to run `pod lib lint BookReader.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'BookReader'
  s.version          = '0.1.0'
  s.summary          = 'Sample code for PDFKit on iOS 11, clone of iBooks.app built on top of PDFKit.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
  https://github.com/kishikawakatsumi/BookReader
  Usage
  Import Your Own PDFs
  The easiest way to import your PDFs is to email your PDF file to your iOS device. Navigate to the email and ensure that the attachment is there. Tap and hold the document attachment icon. This should open a popover on the iPad, or an action sheet on the iPhone, that shows all of the apps that open your document type. BookReader app should show up in the list. Tap BookReader app icon and BookReader app should launch and receive the document from the email.
                       DESC

  s.homepage         = 'https://github.com/iOSDevLog/BookReader'
  s.screenshots      = 'https://raw.githubusercontent.com/iOSDevLog/BookReader/master/Screenshot/0.png', 'https://raw.githubusercontent.com/iOSDevLog/BookReader/master/Screenshot/1.png', 'https://raw.githubusercontent.com/iOSDevLog/BookReader/master/Screenshot/2.png', 'https://raw.githubusercontent.com/iOSDevLog/BookReader/master/Screenshot/3.png',
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'iosdevlog' => 'iosdevlog@iosdevlog.com' }
  s.source           = { :git => 'https://github.com/iOSDevLog/BookReader.git', :tag => s.version.to_s }
  s.social_media_url = 'https://twitter.com/iosdevlog'

  s.ios.deployment_target = '11.0'

  s.source_files = 'BookReader/Classes/**/*'
  
  s.resource_bundles = {
      'BookReader' => ['BookReader/Assets/*.png', 'BookReader/Assets/*.xib', 'BookReader/Assets/*.storyboard']
  }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  s.frameworks = 'UIKit', 'PDFKit'
  # s.dependency 'AFNetworking', '~> 2.3'
  s.swift_version = '4.1'
end

重新生成项目。

代码语言:javascript
复制
$ cd Example
$ pod install --verbose

PDF.png

"org.cocoapods.BookReader" 是默认生成的 PRODUCT_BUNDLE_IDENTIFIER,可以修改,不过执行 pod install 后又变回来了。

Bundle(identifier: "org.cocoapods.BookReader") 可以定位到引入的 framework,想要访问 storyboard,还需要找到 bundle 位置。�

示例中展示了打开 * documentDirectory* pdf 列表和打开一个本地 pdf 文档。

代码语言:javascript
复制
        if let path = Bundle(identifier: "org.cocoapods.BookReader")?.path(forResource: "BookReader", ofType: "bundle") {
            let bundle = Bundle(path: path)
            let storyboard = UIStoryboard.init(name: "BookReader", bundle: bundle)
            
            switch indexPath.row {
            case 0:
                let bookshelfViewController: BookshelfViewController! = storyboard.instantiateViewController(withIdentifier: "BookshelfViewController") as! BookshelfViewController
                self.show(bookshelfViewController, sender: nil)
                break
            default:
                let bookViewController: BookViewController! = storyboard.instantiateViewController(withIdentifier: "BookViewController") as! BookViewController
                
                let fileManager = FileManager.default
                let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
                let contents = try! fileManager.contentsOfDirectory(at: documentDirectory, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
              
                let documents = contents.compactMap { PDFDocument(url: $0) }
                if documents.count > 0 {
                    let document = documents.last!
                    bookViewController.pdfDocument = document
                }
                self.show(bookViewController, sender: nil)
                
                break
            }
        }

编写完成后,上传到 github。

代码语言:javascript
复制
$ git remote add origin https://github.com/iOSDevLog/BookReader.git
$ git push -u origin master
$ git tag '0.1.0'
$ git push --tags

验证

代码语言:javascript
复制
$ pod lib lint
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
) during validation.

[!] BookReader did not pass validation, due to 1 error and 10 warnings.
You can use the `--no-clean` option to inspect any issue.

报错是没有选择正确的 Command Line Tools

CommandLineTools.png

simctl

再运行一次就正常了。

代码语言:javascript
复制
$  pod lib lint

 -> BookReader (0.1.0)
    - WARN  | url: There was a problem validating the URL {:type=>"MIT", :file=>"LICENSE"}.
    - WARN  | url: There was a problem validating the URL https://twitter.com/iosdevlog.
    - NOTE  | xcodebuild:  libpng warning: Input PNG is already optimized for iPhone OS.  Copying source file to destination...

[!] BookReader did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
You can use the `--no-clean` option to inspect any issue.
代码语言:javascript
复制
$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/iOSDevLog/BookReader.git
 * [new tag]         0.1.0 -> 0.1.0

$ pod spec lint

 -> BookReader


 -> BookReader (0.1.0)
    - WARN  | url: There was a problem validating the URL {:type=>"MIT", :file=>"LICENSE"}.
    - WARN  | url: There was a problem validating the URL https://twitter.com/iosdevlog.
    - NOTE  | xcodebuild:  libpng warning: Input PNG is already optimized for iPhone OS.  Copying source file to destination...

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).

提交一下试试。

代码语言:javascript
复制
$ pod trunk push BookReader.podspec
Updating spec repo `master`
warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 7738 and retry the command.
Validating podspec
 -> BookReader (0.1.0)
    - WARN  | url: There was a problem validating the URL {:type=>"MIT", :file=>"LICENSE"}.
    - WARN  | url: There was a problem validating the URL https://twitter.com/iosdevlog.
    - NOTE  | xcodebuild:  libpng warning: Input PNG is already optimized for iPhone OS.  Copying source file to destination...

[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).

添加 --allow-warnings 忽略警告。

代码语言:javascript
复制
$ pod trunk push BookReader.podspec --allow-warnings
Updating spec repo `master`
Validating podspec
 -> BookReader (0.1.0)
    - WARN  | url: There was a problem validating the URL {:type=>"MIT", :file=>"LICENSE"}.
    - WARN  | url: There was a problem validating the URL https://twitter.com/iosdevlog.
    - NOTE  | xcodebuild:  libpng warning: Input PNG is already optimized for iPhone OS.  Copying source file to destination...

Updating spec repo `master`

--------------------------------------------------------------------------------
 ?  Congrats

 ?  BookReader (0.1.0) successfully published
 ?  July 20th, 13:06
 ?  https://cocoapods.org/pods/BookReader
 ?  Tell your friends!
--------------------------------------------------------------------------------

终于成功了。

接下来测试一下。

代码语言:javascript
复制
$ pod try BookReader
Updating spec repositories

Trying BookReader
Performing CocoaPods Installation
Fetching podspec for `BookReader` from `../`
Installing BookReader 0.1.0
Using FBSnapshotTestCase (2.1.4)
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
Opening '/private/var/folders/j9/qgz9nk754036vn2m1gvxj1c00000gn/T/CocoaPods/Try/BookReader/Example/BookReader.xcworkspace'

[!] Automatically assigning platform `ios` with version `11.0` on target `BookReader_Example` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

很好,可以正常运行了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.07.20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • BookReader
  • CocoaPods
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档