カテゴリー : iOS

[iOS] ネットワーク接続状況を確認するライブラリ「Reachability」

iOS アプリで、ネットワーク接続状況を確認するライブラリ「Reachability」がカンタンに使えて便利です。

tonymillion/Reachability · GitHub

[参考]

[XCODE] ネットワーク接続が3GかWifiか圏外かを調べる簡単な方法 – YoheiM .NET

[XCODE] ネットワークが圏外になったり、圏外から圏内に変わった事をアプリ上で知る方法 – YoheiM .NET

[iOS] Localizable.strings 編集後のビルドエラー「validation failed: The data couldn’t be read because it has been corrupted.」の解決方法

iOS アプリ開発で、Localizable.strings 編集後にビルドエラーが発生しました。

エラーメッセージ
validation failed: The data couldn’t be read because it has been corrupted.

原因は、行末のセミコロン ; が抜けていたせいでした。

"Loading..." = "Loading..."

↓(修正)

"Loading..." = "Loading...";

初歩的なミスですが、ビルドするまでエラーが分からなかったので少し悩みました。

[参考]

Localizable.strings編集後に起こるビルドエラー「validation failed: The data couldn’t be read because it has been corrupted.」 – 甘いものが好きです

[iOS] ネットワーク接続状況を確認するライブラリの調査

iOS アプリで使えるネットワークの接続状況を確認するライブラリの調査というか、pod search Reachability しただけ。

% pod search Reachability
 
 
-> GCNetworkReachability (1.3.0)
   GCNetworkReachability monitors the network state on iOS and OS X devices. Supports ARC, GCD, Blocks, IPv4/IPv6 and OS X/iOS.
   - Homepage: https://github.com/GlennChiu/GCNetworkReachability
   - Source:   https://github.com/GlennChiu/GCNetworkReachability.git
   - Versions: 1.3.0, 1.2.1 [master repo]
 
 
-> KSReachability (1.3)
   A better iOS & Mac reachability for a modern age.
   - Homepage: https://github.com/kstenerud/KSReachability
   - Source:   https://github.com/kstenerud/KSReachability.git
   - Versions: 1.3, 1.1, 1.0, 0.0.1 [master repo]
 
 
-> NPReachability (0.1.0)
   Reachability without the suck.
   - Homepage: https://github.com/Abizern/NPReachability
   - Source:   https://github.com/Abizern/NPReachability.git
   - Versions: 0.1.0 [master repo]
 
 
-> Reachability (3.1.0)
   ARC and GCD Compatible Reachability Class for iOS and OS X. Drop in replacement for Apple Reachability.
   - Homepage: https://github.com/tonymillion/Reachability
   - Source:   https://github.com/tonymillion/Reachability.git
   - Versions: 3.1.0, 3.0.0, 2.0.5 [master repo]
 
 
-> SCNetworkReachability (1.0.1)
   Wrapper for SCNetworkReachability methods of SystemConfiguration.framework.
   - Homepage: https://github.com/belkevich/reachability-ios
   - Source:   https://github.com/belkevich/reachability-ios.git
   - Versions: 1.0.1, 1.0.0 [master repo]
 
 
-> VPPReachability (0.1.0)
   VPPReachability Library for iOS simplifies access to the status of a given hostname.
   - Homepage: https://github.com/vicpenap/VPPReachability
   - Source:   https://github.com/vicpenap/VPPReachability.git
   - Versions: 0.1.0 [master repo]

あとは github の star と fork の数とか最終更新日とか確認しただけなんですが、やはり「Reachability」がダントツで多いですね。
tonymillion/Reachability · GitHub

ただ、KVO (Key-Value Observing) を別途、自分で実装するのが面倒なので、KVO まで実装されているものを選ぶとすると「KSReachability」でしょうか。
kstenerud/KSReachability · GitHub

[iOS] アラートダイアログ「Turn Off Airplane Mode or Use Wi-Fi to Access Data.」「データにアクセスするには、機内モードをオフにするか、Wi-Fiを使用して下さい。」の表示方法

iPhone アプリで、機内モードが有効になっていたり、Wi-Fi設定がOFFになっていたりで、ネットが繋がらないときに下記のようなアラートダイアログを表示させる方法をご紹介します。

英語
Turn Off Airplane Mode or Use Wi-Fi to Access Data.

日本語
データにアクセスするには、機内モードをオフにするか、Wi-Fiを使用して下さい。

Xcode にて、Project > TARGETS > Info > Custom iOS Target Properties の項目に、

Application uses Wi-Fi : YES

と設定するだけでOKです。

Info.plist の差分は下記のようになります。

<key>UIRequiresPersistentWiFi</key>
<true/>

設定1つ追加するだけで対応できるなんてカンタンですね!

[参考]

Retina対応させたiPadアプリがRejectされて戻って来た件 | Macで遊んでる

[iOS] TestFlight の使い方

iOS アプリを TestFlight を使って配布するために参考にした情報をまとめ。

TestFlight | How to create an IPA (Xcode 4.3)

テストフライトの使い方 – Using TestFlight

iOSアプリ実機検証 〜 TestFlight配布 | soohei.net

[iOS] アプリのアイコンのテカリを消す設定方法

iPhoneアプリのアイコンのテカリを消す設定方法をメモ。

iphone-app_Icon-already-includes-gloss-effects

info.plist ファイルの「Icon already includes gloss effects」の項目を YES を指定すればOKです。

[参考]

[XCODE] iPhoneアプリアイコンのテカリを消す設定方法 – YoheiM .NET

[iOS] UIRefreshControl を iOS5 対応させるライブラリ「ISRefreshControl」

iOS6 から対応になった UIRefreshControl を iOS5 対応させるライブラリ「ISRefreshControl」の使い方をメモ。

ishkawa/ISRefreshControl · GitHub

ISRefreshControl for iOS – Cocoa Controls

iOS5で動作するUIRefreshControlのライブラリをつくったときの話 – blog.ishkawa.org

ベースは UIRefreshControl なので、これらのドキュメントを見れば良いですね。

UIRefreshControl Class Reference

[iOS6] 引っ張って更新を簡単に実装できる UIRefreshControl を TableView で使ってみる | ラクイシロク

Objective-Cと戦うブログ: iOS6から追加されたUIRefreshControlを試す

UIRefreshControlで引っ張って更新をする #iOS #UITableViewController #UIRefreshControl – Qiita [キータ]

[iOS] NSOperation の maxConcurrentOperationCount を設定して同時実行スレッドを制限する

NSOperation の同時実行スレッドを制限するには maxConcurrentOperationCount を設定することで実現できます。

例えば、メインスレッド以外に最大2スレッドまで実行させたい場合、以下のように設定します。

sharedQueue = [[NSOperationQueue alloc] init];
sharedQueue.maxConcurrentOperationCount = 2;

以上です。

[iOS] NSOperationQueue をシングルトンで扱う方法

NSOperationQueue をシングルトンで扱うために下記のように NSOperationQueue+SharedQueue.h と NSOperationQueue+SharedQueue.m を追加します。

//  NSOperationQueue+SharedQueue.h
 
#import <Foundation/Foundation.h>
 
@interface NSOperationQueue (SharedQueue)
 
+ (NSOperationQueue *) sharedOperationQueue;
- (void)performSelectorOnBackgroundQueue:(SEL)aSelector withObject:(id)anObject;
 
@end
 
#define SHARED_OPERATION_QUEUE [NSOperationQueue sharedOperationQueue]
//  NSOperationQueue+SharedQueue.m
 
#import "NSOperationQueue+SharedQueue.h"
 
@implementation NSOperationQueue (SharedQueue)
 
+ (NSOperationQueue *) sharedOperationQueue {
 
    static dispatch_once_t pred;
    static NSOperationQueue* sharedQueue;
 
    dispatch_once(&pred, ^{
        sharedQueue = [[NSOperationQueue alloc] init];
    });
 
    return sharedQueue;
}
 
- (void) performSelectorOnBackgroundQueue:(SEL)aSelector withObject:(id)anObject {
 
    NSOperation* operation = [[NSInvocationOperation alloc]
                              initWithTarget:self
                              selector:aSelector
                              object:anObject];
    [[NSOperationQueue sharedOperationQueue] addOperation:operation];
    [operation release];
}
 
@end

[参考]

iphone – Sharing NSOperationQueue across View Controllers? – Stack Overflow

Tutorial: Asynchronous HTTP Client Using NSOperationQueue | iPhone Programming Tutorials

objective c – Global NSOperationQueue – Stack Overflow

Cocoa Tutorial: NSOperation and NSOperationQueue | Cocoa Is My GirlfriendCocoa Is My Girlfriend

Library/NSOperationQueue+SharedQueue.h at master · docchang/Library · GitHub

Library/NSOperationQueue+SharedQueue.m at master · docchang/Library · GitHub

[iOS] EXC_BAD_ACCESS の解決方法

iOS アプリ開発でたまに現れる EXC_BAD_ACCESS エラーの解決方法をメモ。

詳しくは下記のサイトを参考にしました。

iOS 開発で、EXC_BAD_ACCESS とさよならするための6つのルール | Zero4Racer PRO Developer's Blog

EXC_BAD_ACCESS エラー事例

実際に、EXC_BAD_ACCESS エラーを発生させたときの問題点は下記の通りです。(随時追記予定)

・NSString の変数に数値を代入していた

以上です。