iOS 8のExtensionでUIApplicationが使えないけど、共通のコードを使いたい場合。


Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 2692

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798
LINEで送る
Pocket

コードをExtensionと共有する方法は、色々あります。
Frameworkを使ったり、それぞれのファイルをコンパイル時に含めてしまうように設定したり、今のところ簡単な方法で出来るなら何でもいいかなと思って色々試してみています。

でも、extensionではUIApplicationを使うことができないので、その辺りを使うコードは共有しにくいのが現状です。
ぼくはこういう場合は、以下の記事に書かれているようにマクロを使って対処しています。

uiapplicationdelegate – iOS 8 Extension How To Detect Running – Stack Overflow



最初に、Extensionの設定でマクロを登録しておきます。
Preprocessor Macrosで、検索してDebugとReleaseのTARGET_IS_EXTENSION=1を両方に追加しています。

App macros 01

#ifdef TARGET_IS_EXTENSION
    // ここにExtension用のコード

#else

    // 通常のコード
    UIApplication *app = [UIApplication shareApplication];

#endif

こんな感じで、使います。
それほど多くの場所では使わないのと、他のアプリでも流用するようなコードでは使わないと決めていますが、お手軽なのでとりあえずこれで解決しています。

これからも更新を続けていきますので、Feedlyへの登録をお願いします!

follow us in feedly

LINEで送る
Pocket


Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

コメントを残す
Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/jagaimopotato/www/html/blog/wp-includes/formatting.php on line 4798