Sparkleを使って自動アップデート確認ボタンを実装する
はじめに
macosアプリを開発するにあたって自動アップデート確認を実装したかった。 それ用のライブラリっぽい Sparkle を利用した。 圧倒的に詰まったし次忘れそうなので手順をメモ。 ついでに同じ内容で困ってる人に届け。
Sparkle: open source software update framework for macOS
動作環境
- Xcode: Version 10.0 (10A255)
- Sparkle: 1.21.2
手順
Podfileに追加
Podfile
に追記します
pod 'Sparkle'
pod install
を実行
更新をチェックボタンを追加
storyboard
,xib
にObject
を追加追加した
object
のcustom class
をUSUpdater
にする更新を確認するボタンを追加して
object
と紐付けるcheckForUpdate
を選択
画面の設定は以上です
SUPublicEDKeyを生成
{project path}/Pods/Sparkle/bin/generate_keys
を実行
sparkleSample kyusuke$ Pods/Sparkle/bin/generate_keys This tool uses macOS Keychain to store the Sparkle private key. If the Keychain prompts you for permission, please allow it. OK! Read the existing key saved in the Keychain. In your app's Info.plist set SUPublicEDKey to: isfUDYEDJDbsjshajfasd72h26JuhfhUHBDY+ytc/58= # ↑を使います
Info.plistを編集
SUFeedURLを設定
- バージョンの確認に利用
- 以降の手順で作る
appcast.xml
を配置するURLを入力します - 置く場所が未定ならgithub pages に置くのが良いと思います
SUPublicEDKey
- 先程出した値を入力します(例だと
isfUDYEDJDbsjshajfasd72h26JuhfhUHBDY+ytc/58=
)
- 先程出した値を入力します(例だと
appをexport
- Product → Archive →Distribute App → Copy App でappをexport
- exportしたフォルダ内の
.app
をzip
する
appcast.xmlを出力
{project path}/Pods/Sparkle/bin/generate_appcast {archived folder}
を実行
sparkleSample kyusuke$ Pods/Sparkle/bin/generate_appcast ~/Desktop/sparkleSample1.1/ Written /Users/kyusuke/Desktop/sparkleSample1.1/sparkleSample.xml based on 1 updates
- 出力した
appcast.xml
のenclosure
にsparkle:edSignature
の記載があるか確認- なければ
{project path}/Pods/Sparkle/bin/sign_update {archived folder/appName.zip}
を実行してappcast.xml
のenclosure
に追記
- なければ
sparkleSample kyusuke$ Pods/Sparkle/bin/sign_update ~/Desktop/sparkleSample1.1/sparkleSample.zip sparkle:edSignature="xxxxxxxxxxxxxxxxxxxxxxxxxxxx" length="11111111"
その他
今回の実装例では発生しなかったけど、疎通周りで結構エラーが出たのでその際の対応
A server with the specified hostname could not be found.
App Transport Security Settings
の設定をInfo.plist
に追加Allow Arbitrary Loads
をYes
にする
launch path not accessible
- {appName.entitlements} の
com.apple.security.app-sandbox
をfalse
にする- 今回だと
sparkleSample.entitlements
- このやり方が正しいのかはだいぶ怪しい
- 今回だと
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.files.user-selected.read-only</key> <true/> <key>com.apple.security.app-sandbox</key> <!-- これと --> <false/> <!-- これと --> </dict> </plist>
所感
sparkleの日本語情報が基本的に古くて、当時と今で認証方法の種類とかファイル名とか細かいところが変わってて結構ハマった。 macosの情報があんまりないので機会があれば書いていきたい。
実装例
releaseから1.0.zipを落としてupdateを試せると思う
参考URL
ありがとうございました
macOS で ネットからURLでダウンロードするコードが動かなくなり焦って調べてみた - Qiita
macアプリ XCode9.4.1より特定のフォルダにアクセスできない問題の回避方法 | まつゆう (@YutakaMatsui)