Archive for the ‘未分類’ Category

バックグランドでもアプリを動かし続けるには?(iOS)

2012年7月16日

UIApplication.applicationDidEnterBackground  で beginBackgroundTaskWithExpirationHandler を呼び出すようにとの資料があったが

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/applicationDidEnterBackground:

beginBackgroundTaskWithExpirationHandler は”You should not use this method simply to keep your application running after it moves to the background.”と書いてあるので、これを使ってはいけない気がするが。。。では、どうしたらいいのだろう’?

しかし、とりあえず beginBackgroundTaskWithExpirationHandler を呼び出す方法を使ってみたところ、エミュレータではちゃんとバックグランドで動いたし、別に問題ないように見える。

Cocoa Application Tutorial の Converterアプリを iPhone に移植

2011年4月9日

Cocoa Application Tutorial (下)の Converterアプリを iPhone に移植してみた。

CocoaTutrial

CocoaTutrial

プロジェクトの選択

NewProjectWindowBased

NewProjectWindowBased

プロジェクトの新規作成では Window-based Application を選択。
このあとは、Cocoa Application Tutorial の指示通りにすすめればOK。(ただし、コントロールのクラス名はNSTextField → UITextField という要領で置き換える。)

変更すべき点

しかし、Controllerの定義と実装には、NSTextField と UITextField の違いにより若干変更が必要。

【ConverterController.h】
★NSTextField を UITextField に置き換える。

@interface ConverterController : NSObject {
	IBOutlet UITextField *amountField;
	IBOutlet UITextField *dollarField;
	IBOutlet UITextField *rateField;
	Converter *converter;
}
- (IBAction)convert:(id)sender;
@end

【ConverterController.m】
★NSTextField にはあるが UITextField にはないメソッドを書き換える。

@implementation ConverterController
- (IBAction)convert:(id)sender {
    float amount;
    converter = [[Converter alloc]init]; 

//    [converter setSourceCurrencyAmount:[dollarField floatValue]];
// UITextField には floatValue がない
    [converter setSourceCurrencyAmount: [dollarField.text floatValue]]; 	

//    [converter setRate:[rateField floatValue]];
// UITextField には floatValue がない
    [converter setRate: [rateField.text floatValue]]; 	

    amount =   [converter convertCurrency];

//    [amountField setFloatValue:amount];
// UITextField には floatValue がない
    [amountField setText: [[NSNumber numberWithFloat: amount] stringValue]]; 

//    [rateField selectText:self];
// UITextField には selectText がない。
// 書き換えができなかったので、保留。

// iOS にはガベージコレクタがないので、リリースする必要がある。
	[converter release];
}
@end


また、数値の入力フィールドについては、キーボードを Number&Punctuation に設定した方が便利。


シミュレーターでの実行結果

Hello world!

2011年1月15日

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!