Go to file
Alfred Gao 681166fb6d change travis to xcode9.2 2018-02-26 16:17:46 +08:00
Example add pod description 2017-01-05 16:59:23 +08:00
Sources adjust for swift4 2018-02-26 15:49:22 +08:00
packager packager wit Swift4 2018-02-26 16:10:10 +08:00
.gitignore upgrade to swift4 2018-02-24 18:13:09 +08:00
.swift-version upgrade to swift4 2018-02-24 18:13:09 +08:00
.travis.yml change travis to xcode9.2 2018-02-26 16:17:46 +08:00
CHANGELOG.md add comments for 1.4.0 2018-02-26 16:14:21 +08:00
LICENSE Initial commit 2017-01-05 16:30:03 +08:00
Package.swift adjust for swift4 2018-02-26 15:49:22 +08:00
README.md add language sufix support 2017-02-04 14:45:49 +08:00
ResourcePackage.podspec upgrade to swift4 2018-02-24 18:13:09 +08:00
_Pods.xcodeproj Initial commit 2017-01-05 16:30:03 +08:00
structure.monopic add structure picture 2017-01-06 17:45:09 +08:00
structure.png add structure picture 2017-01-06 17:45:09 +08:00

README.md

ResourcePackage

CI Status Version License Platform

将 app 资源打包加密进行管理。

Package resources to a single file, and access them via file name as key.

Requirements

  • iOS 9.0+, OSX 10.12+

Installation

TextFormater 可通过CocoaPods安装:

ResourcePackage is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ResourcePackage"

Structure

Structure

Usage

Packager - 打包工具

git clone https://github.com/1Fr3dG/ResourcePackage.git
cd ResourcePackage
cd packager
swift build -c release
.build/release/packager

可使用该打包工具将资源目录打包为单个文件供 app 使用。

This tool designed to package a resource folder to a single file, for used by app.

Note: This tool support only gzip as compress algorithm, you can build your own tool to support more.

Open a package

let _compress: SimpleEncrypter = EncrypterCompress(with: "gzip")
let _encrypt: SimpleEncrypter = EncrypterXor(with: "password12345")
let _pkgfile: String = "filename"
let pkg = ResourcePackage(with: _pkgfile, encrypter: _encrypt, compressor: _compress)

Open packages with package reader

let pkgReader = ResourcePackageReader(
        withCache: false,
        useTwoStepLocating: false,
        autoDeviceCustomization: false,
        useKeyPrefix: false)
pkgReader.packages["pkg1"] = pkg

let themePkgReader = ResourcePackageReader(withTheme theme: String,
                            FromThemePackages respkg: ["themePkg1" : themePkg],
                            withBackwardTheme backward: "default")

Read data

let stringValue = String(data:pkgReader[keyofString], encoding: .utf8)
let imageValue = UIImage(data:pkgReader[keyofImage])

Resource Priority

  • resource package priority is reverse order of package key

  • pkgReader[key] will looking for resource with following order:

    • [key+model+lang]
    • [key+model]
    • [key+devicetype+lang]
    • [key+devicetype]
    • [key+lang]
    • [key]

    ** NOTE: it will ONLY search the package with [key] resource **

  • for two step locating, sufix will NOT applied for 2nd search, but all packages will be included

Use UIExtensions

uibutton.loadTheme(from: themePkgReader, key: "button1")
uilable.setText(from: themePkgReader, key: "labeltext")
uiimageview.setImage(from: themePkgReader, key: "image1")
  • uibutton.loadTheme
    • key.title -> uibutton.attributedTitle
    • key.image -> uibutton.image
    • key.bgimg -> uibutton.backgroundImage
    • key.disabled.above
    • key.highlighted.above
    • key.selected.above
    • key.focused.above
  • uilabel.setText
    • key -> uilabel.attributedText
  • uiimageview.setImage
    • key -> uiimageview.image
    • key.highlighted -> uiimageview.highlightedImage

Sounds

pkgReader.playSound(key: "asound", withVibrate: false)
pkgReader.playMusic("bgmusic.mp3", loops: 1, volume: 0.8)

Author

Alfred Gao, alfredg@alfredg.cn

License

ResourcePackage is available under the MIT license. See the LICENSE file for more info.