提交 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 条评论
登录 后参与评论

相关文章

来自专栏Seebug漏洞平台

花式窃取NetNTLM哈希的方法

原文:https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-ha...

3138
来自专栏海天一树

小朋友学C++(21):命名空间

这里的第一行,#include好理解,iostream是输入输出流,包含了输入流istream和输出流ostream。 第二行using namespace s...

1104
来自专栏施炯的IoT开发专栏

Battery Status on Windows Mobile

    大家知道,我们可以通过Start->Settings->Systems->Power来查看系统的电池情况,包括电池的类型,剩余的电量等等,如下图1所示:...

2016
来自专栏码匠的流水账

解决jd-gui在Sierra下闪退问题

在升级了mac操作系统到Sierra版本之后,之前的jd-gui就闪退了,本文就讲述一下如何解决这个问题。

2231
来自专栏杨建荣的学习笔记

一条细小的报警短信的处理(r6笔记第96天)

最近偶尔会收到一封报警短信,提示内容大体如下, xxxx,trc_directory (TNS-1190),log_directory(TNS-1190),Pl...

3668
来自专栏向治洪

多线程下载

楼主三年磨剑(当然不是磨着一把剑),倾血奉献Android多线程下载Demo。有的人就问了“怎么写来写去还是Demo?”,因为老哥我实在太忙了, 每天写一点...

1898
来自专栏Kotlin入门系列

win7基础 cmd 查看当前已经启动的服务列表

4026
来自专栏程序员互动联盟

【开发指南】如何为nexus 5编译固件

nexus 5是谷歌的亲儿子,而android的源码是开源的,那如果我有一个nexus 5手机,为何不自己为nexus 5编译软件呢? 开搞,本文假定已经有an...

38912
来自专栏向治洪

Rxjava + retrofit + dagger2 + mvp搭建Android框架

最近出去面试,总会被问到我们项目现在采用的什么开发框架,不过据我的经验网络框架(volley)+图片缓存(uIl)+数据库(orm)+mvp,不过现在这套框架比...

22410
来自专栏吉浦迅科技

看人家用Jetson TK1如何搭集群

1243

扫码关注云+社区