Archive

Archive for 5月, 2009

iPhoneでダイジェスト認証

5月 19th, 2009

NSURL *URL = [NSURL URLWithString:@"ダイジェスト認証がかかったアドレス"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
[connection start];
以上で開始し、

-(void)connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential = [NSURLCredential credentialWithUser:@"ユーザー名" password:@"パス" persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
で一旦受ける。
(※http://stackoverflow.com/questions/589377/in-the-iphone-sdk-how-would-you-programatically-pass-a-username-password-to-a
を参考にさせていただきました。)

上記でユーザー名、パスが正しく送り返されれば、その他のdelegate、
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
などに情報が来る。

kuni プログラム

最近調べた子ネタ

5月 14th, 2009

■ホーム画面のアプリアイコン横に数字を表示
[UIApplication sharedApplication].applicationIconBadgeNumber = N;
[UIApplication sharedApplication].applicationIconBadgeNumber = 0; で消える。

■ホーム「設定」アプリ内の設定部分に自分のアプリの設定画面を入れる

http://developer.apple.com/jp/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationSettings/ApplicationSettings.html#//apple_ref/doc/uid/TP40007072-CH13-SW10


http://ameblo.jp/xcc/entry-10172820087.html

※アプリから読み取るときは、
BOOL testValue = [[NSUserDefaults standardUserDefaults] boolForKey(型に合わせて変えるstringForKey、など):@”enabled_preference(Identifierに書かれている物を入れる)”];

■Facebook connectのiPhoneSDKをOS3.0で動かしたときのコンパイルエラーを取り除く

http://forum.developers.facebook.com/viewtopic.php?pid=143467

※エラー部分をコメントアウトするだけでOKっぽい。

■tableViewに「次を読み込む」処理を入れる

http://d.hatena.ne.jp/KishikawaKatsumi/20090118/1232224534

※これ、基本的に手動だったんですね..app storeアプリとか、apple純正のやつでも使われているから、
SDKで用意されているのかと思っていた..

■textの高さを取る
CGSize tempSize = CGSizeMake(320 , 999);
CGSize textSize = [NSStringObj sizeWithFont:UIfontObj constrainedToSize: tempSize];
NSLog(@”%f , %f” , textSize.width , textSize.height);
※ただし、行間は設定できない模様..
やはり、styleでline-Height設定をしたhtmlをUITextViewに読み込むしかなさそう。
UILabel、UITextViewなどでも行間や字間くらい出来ても良さそうなんですけどね…

■MD5文字列を生成

http://miketeo.net/wp/index.php/2008/09/22/calculating-md5-digest-with-iphone-sdk.html

■status barにインジケーターを表示(ネットワーク要求があれば自動的に出るという訳ではなかったんですね…)
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

kuni プログラム