GoogleカレンダーAPIで終日の予定を登録する

NSDateComponentsを使って年月日のみを有効にします。

[sourcecode language=”cpp”]
GDataEntryCalendarEvent *newEvent = [GDataEntryCalendarEvent calendarEvent];
GDataDateTime *startDateTime = [GDataDateTime dateTimeWithDate:salesDate
timeZone:[NSTimeZone systemTimeZone]];

unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *comps = [[NSCalendar currentCalendar] components:unitFlags fromDate:salesDate];
[startDateTime setDateComponents:comps];
GDataWhen *when = [GDataWhen whenWithStartTime:startDateTime
endTime:nil];

[newEvent addTime:when];
[/sourcecode]

他のアプリがインストール済みかどうかを取得する

[sourcecode language=”cpp”]
if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"inetdual://"]] ) {
// ここに連携メニューなどのコードを書く
}
[/sourcecode]

前提:他のアプリが独自スキームを実装していること

「お好み発売日情報」ではこの方法で「詳細をiNetDualで開く」リンクの表示を切り替えています。ちょっとした技ですが、動作しないメニューを表示したままにすると審査でリジェクトされるため、連携用のメニューの表示切り替えに使えると思います。

自動回転のサンプル

Safariと同じようにするには、以下のように実装します。

[sourcecode language=”cpp”]
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
[/sourcecode]

こっちはNG。EvernoteやSimpleMind Xpressなど、この実装をしているアプリがたくさんありますが、iPhoneを逆さまにして見るというニーズはないと思います。

[sourcecode language=”cpp”]
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
[/sourcecode]