はじめに
こんにちは。CX事業本部の平屋です。
最近、サポートOSをiOS 14以上に変更する作業を実施したので、その内容を紹介します。
検証環境
- macOS Monterey 12.6
- Xcode Version 13.4
(1) サポートOSを14以上にする対応
まずは、サポートOSを14以上に変更しました。
(1-1) アプリ本体
Xcodeプロジェクトの設定(またはターゲットの設定) > 「Build Settings」 > 「iOS Deployment Taeget」の値を「iOS 14.0」に変更します。(キーワードIPHONEOS_DEPLOYMENT_TARGET
でフィルタリングすると見つけやすいです)
(1-2) CocoaPods管理下のライブラリ
CocoaPodsを使っている場合は、各ライブラリのサポートOSも変更します。Podfileに以下のスクリプトを追加し、pod install
を実行しました。
platform :ios, '14.0'
# ...
post_install do | installer |
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
end
end
end
(2) サポートOSを14以上にしたことで発生したwarningの解消
次に、サポートOS変更によって発生したwarningを解消しました。今回の作業で発生したwarningは以下の4件でした。
(2-1) CLLocationManagerの非推奨クラスメソッドを使わないように修正
authorizationStatus()が非推奨になっていたのでauthorizationStatusを使うように修正しました。
// 修正前
let status = CLLocationManager.authorizationStatus()
// 修正後
let status = CLLocationManager().authorizationStatus
(2-2) CLLocationManagerDelegateの非推奨メソッドを使わないように修正
locationManager(_:didChangeAuthorization:)が非推奨になっていたのでlocationManagerDidChangeAuthorization(_:)を使うように修正しました。
// 修正前
extension MOPLocationTrackingUseCase: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
// statusを使う処理
switch status {
//...
}
}
}
// 修正後
extension MOPLocationTrackingUseCase: CLLocationManagerDelegate {
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
// statusを使う処理
switch manager.authorizationStatus {
// ...
}
}
}
(2-3) UNNotificationPresentationOptionsの非推奨プロパティを使わないように修正
alertが非推奨になっていたので、list及びbannerを使うように修正しました。
// 修正前
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.sound, .alert])
}
// 修正後
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// list及びbannerを使うように修正
completionHandler([.sound, .banner, .list])
}
(2-4) SKStoreReviewControllerの非推奨クラスメソッドを使わないように修正
以下の記事を参考にして対応しました。
(3) iOS 14以上/未満の条件分岐を削除
最後に、iOS 14以上/未満の条件分岐があれば削除します。
// 修正前
if #available(iOS 14.0, *) {
// iOS 14以上の場合の処理
// ...
} else {
// Fallback on earlier versions
}
// 修正後
// iOS 14以上の場合の処理
// ...