LoginSignup
136
135

More than 5 years have passed since last update.

iOS 9 / watchOS 2 で deprecated になる or 引退していくAPIたち

Last updated at Posted at 2015-09-26

これは何

iOS 9 / watchOS 2 では様々なAPIが追加されましたが、同時に消え行くAPIにも焦点を当ててみました。(全部は網羅していません)

iOS 9でdeprecatedになったAPIたち

UIAlertView

iOS 8から非推奨扱いになった UIAlertView ですが、iOS 9からは正式に deprecated になりました。

NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead")

(iOS 8までは非推奨とはされていたものの NS_CLASS_DEPRECATED_IOS 指定ではなかった)

今後は UIAlertController を使うことが推奨されています。

ちなみに、UIActionSheet は iOS 8.3 で正式に deprecated 指定になっています。

NSURLConnection

iOS 9.0 - What's New in iOS の「Deprecated APIs」に

The NSURLConnection API in the Foundation framework. Use NSURLSession APIs instead.

とあります。

今後は iOS 7 から追加された NSURLSession を使うことが推奨されています。

application:handleOpenURL:

次の2メソッドが deprecated になっています。URLスキームでアプリを起動した時に呼ばれるお馴染みのメソッドですね。

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation;

iOS 9からは次のメソッドが推奨されています。

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options NS_AVAILABLE_IOS(9_0);

sourceApplicationannotation の引数が options にまとめられたようですね。

今後は options から下記のキーを利用して値を取り出すことになりそうです。

  • UIApplicationOpenURLOptionsSourceApplicationKey
  • UIApplicationOpenURLOptionsAnnotationKey
  • UIApplicationOpenURLOptionsOpenInPlaceKey

UIPopoverController

UIPopoverController も deprecated です。

スクリーンショット 2015-09-26 13.00.39.png

ヘッダファイルには次のような記載がありました。

UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController.

今後は


myPopoverViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:myPopoverViewController animated: YES completion: nil];

のように使うのが推奨されているようです。

Address Book UI frameworks

iOSの連絡先アプリからアドレスデータを取得するフレームワークですね。

views_2x.png

昔作っていたアプリで使っていたのですが、これも deprecated です。

公式ドキュメントに

The Address Book and Address Book UI frameworks. Use the Contacts and Contacts UI frameworks instead.

とあるように、今後は Contacts UI frameworks を使うことが推奨されています。

Contacts UI frameworks の使い方については、下記の記事を参考にしてください。

watchOS 2で引退したAPIたち

これらは deprecated ではなく引退です。つまり、使用することができません。(ビルドエラーになります)

イメージキャッシュ系API

WKInterfaceDevice のイメージキャッシュが不可になっています。

- (BOOL)addCachedImage:(UIImage *)image name:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
- (BOOL)addCachedImageWithData:(NSData *)imageData name:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
- (void)removeCachedImageWithName:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
- (void)removeAllCachedImages WK_AVAILABLE_IOS_ONLY(8.2);
@property (nonatomic, readonly, strong) NSDictionary<NSString*, NSNumber*> *cachedImages WK_AVAILABLE_IOS_ONLY(8.2);

watchOS 1では、Watch ExtensionがiPhone側で動いていたため、画像リソースをWatch側にキャッシュしておくことに意味がありましたが、watchOS 2ではWatch ExtensionがApple Watch側で動くため、これらのメソッドは意味を成さなくなりました。

NSURLConnection

The NSURLConnection class should no longer be used. NSURLSession is the replacement for NSURLConnection

iOSと同様、こちらも NSURLSession に切り替える必要があります。

CoreLocationの一部メソッド

位置情報を継続的に取得するメソッドが軒並み __WATCHOS_PROHIBITED になっています。


- (void)startUpdatingLocation __WATCHOS_PROHIBITED;
- (void)startUpdatingHeading __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0) __WATCHOS_PROHIBITED;
- (void)startMonitoringSignificantLocationChanges __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0) __WATCHOS_PROHIBITED;
- (void)startMonitoringForRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_TBD,__IPHONE_5_0) __WATCHOS_PROHIBITED;

(↑全部は網羅していません)

これも WatchKit Extension が Apple Watch 側に移動したことが理由だと思われます。

今後は一度きりの位置情報測定が可能な


- (void)requestLocation __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_9_0);

を使うことが推奨されています。

さいごに

引退したAPIの皆さま、本当にお疲れ様でした!! :bow:

リンク

136
135
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
136
135