专栏首页iOSDevLog提交 BookReader Framework 到 CocoaPodsBookReaderCocoaPods

提交 BookReader Framework 到 CocoaPodsBookReaderCocoaPods

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

$ 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
$ 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 版本信息。

#
# 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

重新生成项目。

$ 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 文档。

        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。

$ git remote add origin https://github.com/iOSDevLog/BookReader.git
$ git push -u origin master
$ git tag '0.1.0'
$ git push --tags

验证

$ 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

再运行一次就正常了。

$  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.
$ 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).

提交一下试试。

$ 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 忽略警告。

$ 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!
--------------------------------------------------------------------------------

终于成功了。

接下来测试一下。

$ 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`.

很好,可以正常运行了。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Learn Android Studio 3Android architectureAndroid ComponentsDesign editor.pngKeyboard Shortcuts for

    iOSDevLog
  • Ubuntu安装Weblate

    This is the recommended method if you don’t want to concern yourself with furthe...

    iOSDevLog
  • Mac酷炫Terminal 样式iTerm2 + oh-my-zsh

    在开始使用Mac Terminal下指令开发App时,常常会遇到搞不清楚专案是不是已经加入Git版控与目前到底位于什么分支之下。面对这样的窘境,身为专业的程式开...

    iOSDevLog
  • 使用TensorFlow物体检测模型、Python和OpenCV的社交距离检测器

    疫情期间,我们在GitHub上搜索TensorFlow预训练模型,发现了一个包含25个物体检测预训练模型的库,并且这些预训练模型中包含其性能和速度指标。结合一定...

    小白学视觉
  • IPRally正在构建一个基于知识图的专利搜索引擎

    来自芬兰的一家新兴初创公司IPRally旨在解决专利检索问题,它已经筹集了200万欧元的种子基金。

    用户8054111
  • IPRally正在为专利构建基于知识图的搜索引擎

    IPRally是芬兰新兴的初创企业,旨在解决专利搜索问题,已筹集了200万欧元的种子资金。

    木樾233
  • 嵌入式编程中的复杂指针的使用

    在C语言编程中,指针是最容易出错的地方,尤其是在很多指针同时出现的时候,看的眼花缭乱的,本文从嵌入式中常用的复杂角度进行分析,彻底搞清楚c语言中的容易弄错的指针...

    bigmagic
  • JavaScript之充实文档的内容

    1、我们在平时的开发中会碰到一些缩略语如:XML,HTML,API等专业术语;为了能使用户,更好的了解术语的意思,我们通常会给<abbr></abbr>标签加一...

    郑小超.
  • 从语义特征预测对象之间的相对深度(cs,AI)

    视觉和语言任务,如视觉关系检测和视觉问题回答,受益于语义特征,并且为语言提供适当的基础。二维图像中描绘的物体的三维深度就是这样一个特征。然而,如果不学习与场景相...

    天然 8129060
  • 2020-08-31:描述HTTP的版本之间的区别,主要是1.0/1.1/2.0三个版本的区别。

    HTTP1.0:允许即使有Body也不用Content-Length,可以用断开连接的方式表示Body结束。

    福大大架构师每日一题

扫码关注云+社区

领取腾讯云代金券