WatchOS開源應用:BeijingAirWatch
WatchOS 2.0 Complication of Real-time Air Quality for Major Chinese Cities 蘋果表盤實時刷新北上廣沈蓉空氣質量
- Real-time PM 2.5 readings for major Chinese cities right on your clock face.
- All five major Chinese cities included: Shanghai, Beijing, Guangzhou, Shenyang and Chengdu.
- Closely tracks the latest data with a maximum delay of 10 minutes.
- A clean and consice complication widget that fits perfectly on your every clock face.
- 在你的蘋果手表表盤上追蹤最新空氣污染數據。
- 支持城市: 上海、北京、廣州、沈陽和成都。
- 實時后臺刷新,最大延遲小于10分鐘。
- 精美 complication 視圖,適配所有表盤。
Don't Take Clean Air for Granted 空氣質量與健康息息相關
Where the Data Come from? 數據源
- http://shanghai.usembassy-china.org.cn/airmonitor.html
- http://beijing.usembassy-china.org.cn/070109air.html
- http://guangzhou.usembassy-china.org.cn/guangzhou-air-quality-monitor.html
- http://www.stateair.net/web/post/1/5.html
- http://chengdu.usembassy-china.org.cn/air-quality-monitor4.html
How to Install 如何安裝
- Make sure you have an iPhone paired with an Apple Watch.
- Connect your iPhone to your Mac computer.
- Clone the project.
- Run the complication target on your iPhone.
- Let Xcode help you if there's any code signing error.
- When you see logs appearing in the Xcode console, the installation is done. Hit the stop button.
- 準備好 iPhone 和與之匹配的蘋果手表
- 將 iPhone 連接到電腦上
- 將源代碼克隆到本地
- 運行 complication target
- 如果出現代碼簽名錯誤,讓 Xcode 嘗試自動解決。
- 當 Xcode 控制臺開始打印日志時,說明安裝已經完成。點擊停止按鈕。
How to Set-up the Complication 如何設置表盤 Complication
- Go to your watch. Force touch to customize. Find the complication named PM2.5.
- If the reading is not ready yet, you will see Press to Refresh (or ?? if the comllication style you choose is a smaller one.).
- Press the complication to see the watch app.
- In the watch app, press the City button to select your city.
- Also in the watch app, press the Refresh button to force-start the initial refresh.
- When the watch app is done refreshing, you will find meaningful data displayed right above the refresh and city buttons.
- If the refresh takes too long to finish, try kill the app and start all over.
- When the refresh is done, hit the digital crown to go back to the clock face.
- It's possible that when back to the clock face, you are still seeing the Press to Refresh (or ??) text instead of the air quality reading. If that's the case, force touch to switch to another clock face that doesn't have this complication, and then switch back. By now you should see the correct reading.
- 用力按壓表盤,進入自定義表盤模式,找到名字叫 PM2.5 的 Complication。
- 如果實時刷新數據尚未就緒,你將會看到 Press to Refresh 字樣(或者是 "??" 字樣,如果你選擇的 Complication 樣式比較小)。
- 點擊 Complication,進入對應的 Watch App。
- 在 Watch App 中,點擊 City 按鈕選擇城市。
- 仍然在 Watch App 中,點擊 Refresh 按鈕觸發第一次強制刷新。
- 如果刷新成功,你會在按鈕上方看到最新的空氣污染數據。
- 如果刷新緩慢,試試殺掉 app,從頭開始。
- 刷新成功以后,按壓電子旋鈕回到表盤。
- 刷新成功并回到表盤時,你仍然可能看到不正常的 Press to Refresh 字樣(或者 ?? 字樣)。這是由于表盤 UI 刷新延遲造成的。你可以通過在多個不同表盤間來回切換的辦法,強迫 WatchOS 刷新表盤。
Auto-refresh is Implemented Using VOIP 后臺自動刷新實現機制
- This app implements auto-refresh using the VOIP method. The minimum refresh interval is 10 minutes.
- The refresh will pause as soon as the current hour's readings are fetched. The refresh will resume automatically in the next hour.
- After you reboot your iPhone, you may need to use the watch app's refresh button to restart the companion iOS app's VOIP auto-refresh callback.
- 后臺自動刷新采用了 VOIP 接口實現。刷新的頻率為 10 分鐘一次。
- 因為數據源是每小時刷新一次。所以我們在刷新時,如果發現當前小時的數據已經取到了,刷新就會暫停。在進入下一個小時后,刷新會再次啟動。
- 如果你重啟了手機,VOIP 刷新可能會停止。你可以通過在 Watch App 中點擊 Refresh 按鈕的方式強迫喚醒 VOIP 刷新。
Enable the Hiddeng Debug Mode 開啟隱藏的 Debug 模式
- If you want to dive in and play around, go to the CommonUtil.swift, set DEBUG_LOCAL_NOTIFICATION to true. Delete and reinstall the app, debug information will start popping up from time to time as local notifications.
- 如果你想深入了解代碼每時每刻的工作狀況,去 CommonUtil.swift 里面,將 DEBUG_LOCAL_NOTIFICATION 設為 true 。刪掉然后重裝 app。代碼的工作情況將會以本地通知的形式呈現在你眼前。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!