[iOS]Storyboards(その3)
もし、画面が遷移したタイミングを知りたいのなら、元のビュー・コントローラでUIViewControllerの- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)senderメソッドをオーバーライドする。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DBGMSG(@"%s", __func__);
DBGMSG(@"segue identifier:%@", [segue identifier]);
}
Segueに"segue01"というidをつけたので、それがデバッグ出力されるはずだ。
ここで画面遷移となった原因に対応した状態をDocumentに保存する等すれば、遷移理由に対応した処理が出来るはずだ。
ソースコード
GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/ios/Storyboards - GitHub
関連情報
Converting to Storyboards Release Notes
Your Second iOS App: Storyboards
iOS Developer Libraryの情報です。
[iOS]Storyboards(その2)
前回作成したストーリーボードに追加したViewControllerを削除して、NavigationControllerを追加し、カスタムクラスでRootViewControllerとSubViewControllerを追加する。
RootViewControllerにはボタンあって、ボタンとSubViewControllerをPushのSegueでつなぐ。
シミュレータで動作確認。
以前、Documentクラスを紹介したが、ストーリーボードを使用する場合、各ビュー・コントローラが個別に存在してる感じなので、シングルトンでアクセスできるのは便利だと思う。状態がDocumentクラスに保持されていれば、このコードだけでそれなりの実装が出来ると思う。
ソースコード
GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/ios/Storyboards - GitHub
関連情報
Converting to Storyboards Release Notes
Your Second iOS App: Storyboards
iOS Developer Libraryの情報です。
[Android]hello, world(その2)
トラブルの原因が分かった。debug.keystoreが期限切れだった。
~/.android/debug.keystoreを削除するなり、ファイル名を変更するなりして、再度、RUNを実行すればOK!
ということで、予定通り入門編をすすめる。
今回は、どこでもある、"hello, world"
新規Androidプロジェクトを作成する。
プロジェクトが作成された。
実行。
ソースコード
GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/android/HelloWorld - GitHub
関連情報
Android Developers
Android開発者サイトです。
[Android]hello, world
ソフトウェア開発者、それもアプリケーション開発者ならAndroid開発を学ばない理由はないだろう。
特に、複数のプラットフォームに接する事によって、設計思想的に得る物は多いはずだ。
開発環境の設定については、多くの情報が公開されているので、ここで説明する必要はないだろう。著者は普通にEclipse上で開発を行っている。
ただ、申し訳ないが、AndroidプロジェクトのどのパートをGitHubで公開するといいのか理解していない為、今回はソースコードの公開なしで許して欲しい。
と、ここまで書いて、開発環境の更新に手間取り、これ以上、進めなくなってしまった。
申し訳ないが、今回はここまでとさせて欲しい。
※その後、環境構築失敗の原因が分かった。後で試す。
関連情報
Android Developers
Android開発者サイトです。
[iOS]Storyboards
先日のCocoa勉強会の復習だ。
Empty Applicationを生成する。
Storyboardファイルを新規作成する。
Main Storyboardに、さっき作成したStoryboardファイルを設定する。
ViewControllerを追加する。追加した物かどうか、分かりやすくする為、背景を黄色に設定。
アプリケーション・デリゲートでwindowプロパティの生成をコメントアウトする。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/*
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
*/
return YES;
}
実行する。
今回はここまで。
ソースコード
GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/ios/Storyboards - GitHub
関連情報
Converting to Storyboards Release Notes
Your Second iOS App: Storyboards
iOS Developer Libraryの情報です。
[Mac][Aruduino]Aruduinoハンズオンセミナー初級編
AppleStore銀座で開催されたAruduinoハンズオンセミナー初級編に参加してきた。
今回は、その復習の結果だが、素人なので間違いがある可能性がある。その場合は指摘してくれると嬉しい!
オームの法則
I=(1/R)*V[A]
I:電流[A]
V:電圧[V]
1/R:比例定数。
R:電気抵抗[Ω]
発光ダイオード(LED)
Arduinoからの電源電圧は5V、LEDの順方向降下電圧は3.5V(予想)、セミナーで使用した抵抗は1,600Ω(だと思う)
電流 = 電圧 ÷ 抵抗 = (5V - 3.5V) ÷ 1.6kΩ ≒ 1mA
つまり、1mAの電流を流れる事を期待したということか。
プルアップ抵抗/プルダウン抵抗
回路にOn/Offするスイッチを入れた場合、Off時は断線した状態。つまり、電圧不定の状態になる。プルアップの場合、例えば、5Vの電源と間に10kΩの抵抗を入れてつなぐと、0.5mA(=5V÷10kΩ)と低い電流で安定することになる。そして、スイッチをOnにすると抵抗値が低い側に電流が流れるので、望みどおりとなる。
プルダウンの場合、スイッチがOffの際、マイコンの0Vの端子と接続させて安定させ、Onの際に5Vの端子と接続させるということか。まだ、説明していて自身がない。
今回は、基礎的な話なので、今後は、Arduinoとの関係について調べて説明していきたい。
関連情報
Arduino
本家のホームページです。
Arduino 日本語リファレンス
助かります。ありがとうございます。
TETRASTYLE-dev-BLOG
Aruinoハンズオン(銀座)やりました
iOSとArduinoの情報が豊富です。
関東第50回Cocoa勉強会
関東第50回Cocoa勉強会
日時: 2012/02/04(土) 13:00-18:00
会場:松戸シティホテルSENDAN-YA
今回は、USBパラレル変換モジュールをMacに接続してみる、ストーリーボードとセグウェ、スペルチェッカー、Local Notificationと通知センター、アクションシートのバグの発表があった。
関連情報
Cocoa勉強会(関東)
[iOS]Local Notification
Notificationには、LocalとPushの二種類があって、前者は発生源が手元のアプリケーション、後者は発生源が外部という事のようだ。
Local Notificationの登録は、通知する日時を指定する方法と、直ぐに通知する方法の二通りがある。
通知する日時を指定する手順は以下のとおり。
- (IBAction)scheduleNotification:(id)sender
{
DBGMSG(@"%s", __func__);
NSDate *today = [NSDate date];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [today dateByAddingTimeInterval:10];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithString:NSLocalizedString(@"Local Notify", nil)];
localNotif.alertAction = NSLocalizedString(@"local notify", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber + 1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"local notify" forKey:@"Key"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
UILocalNotificationのプロパティfireDateに、通知する日時を設定する。上記の例は、現在の時刻の10秒後だ。
UILocalNotificationのインスタンスをUIApplicationのscheduleLocalNotification:メソッドに設定すると、指定された日時に通知される。
直ぐに通知させたい場合は、presentLocalNotificationNow:メソッドを呼ぶ。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
DBGMSG(@"Application entered background state.");
NSAssert(self.bgTask == UIBackgroundTaskInvalid, nil);
self.bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});
}];
dispatch_async(dispatch_get_main_queue(), ^{
while ([application backgroundTimeRemaining] > 1.0) {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = [NSString stringWithString:NSLocalizedString(@"background", nil)];
localNotif.alertAction = NSLocalizedString(@"action", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber + 1;
[application presentLocalNotificationNow:localNotif];
break;
}
}
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});
}
通知を受けてアプリケーションを呼び出す場合は、アプリケーション側で準備が必要となる。
アプリケーションの起動されていない場合は、アプリケーションのデリゲートのdidFinishLaunchingWithOptions:メソッドで通知からの呼び出しかどうかの判断を行う。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *value = [localNotif.userInfo objectForKey:@"Key"];
DBGMSG(@"%s, Notify: %@", __func__, value);
application.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber - 1;
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
起動済みの場合は、didReceiveLocalNotification:メソッドが呼ばれる。
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
NSString *value = [notif.userInfo objectForKey:@"Key"];
NSLog(@"%s, Notify: %@", __func__, value);
app.applicationIconBadgeNumber = notif.applicationIconBadgeNumber - 1;
}
ソースコード
GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/ios/LocalNotification - GitHub
関連情報
Local and Push Notification Programming Guide
iOS Developer Libraryの情報です。
[Mac][Arduino]Getting Started
今回は、Arduinoだ。
まずは、Arduinoを入手しないと話にならない。私はスイッチサイエンスの製品をAmazonで購入した。
ArduinoとMacとは、USBケーブルで接続となるとなるがA-Bタイプを購入する事。A-miniBは別物だ!私はそれで失敗した。
製品が入手できたら以下のサイトの説明通りにすればいい。
http://arduino.cc/en/Guide/MacOSX
ただ、私の場合だと思うが、入手したArduino UNO R3は、初期状態でExamples/1.Basics/Blinkがアップロードされている様で、この手順で試しても最初は変化が分からなかった。
関連情報
Arduino - HomePage
本家のホームページ。
スイッチサイエンス
初心者のため、よく分かっていないが、ここで購入するのが楽そうだ。