2012年2月10日金曜日

iPhoneのPush

とりあえず、SandBox使用の場合

1) App IDではちゃんと開発用のPushの設定をしておく
2) Pushが使えるProvisioningで署名をする
3) 1. で取得した証明書とか秘密鍵でp12ファイルを作って、サーバーにおいておく

3を忘れてひどい目にあったので、めもめも。

2012年2月8日水曜日

YouTube API for Objective-C(iPhone)

設定はここを見れば、大体問題なし(YouTube APIになっていないところは、適宜直す)。

xxx.hでは
#import "Headers/GDataYouTube.h"
#import "Headers/GDataServiceGoogleYouTube.h"

を記述した上で、プロパティにGDatFeedYouTubeVideo*を設定しておく。

特定ユーザのフィードを検索するにはviewDidLoadあたりで

    GDataServiceGoogleYouTube *service = [self youTubeService];
    NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForFeedID:nil];
    GDataQueryYouTube* query = [GDataQueryYouTube 
            youTubeQueryWithFeedURL:feedURL];
    [query setStartIndex:1];
    [query setMaxResults:5];
    [query setAuthor:@"ユーザ名"];
    [query setOrderBy:@"published"];
   
    [service fetchFeedWithQuery:query delegate:self
          didFinishSelector:@selector(request:finishedWithFeed:error:)];
   
    [super viewDidLoad];       


とやっておく。

youTubeServiceは
- (GDataServiceGoogleYouTube *)youTubeService {
    static GDataServiceGoogleYouTube* _service = nil;
    if (!_service) {
        _service = [[GDataServiceGoogleYouTube alloc] init];
        [_service setUserAgent:@"てきとうに"];
    }
   
    // fetch unauthenticated
    [_service setUserCredentialsWithUsername:nil  password:nil];
    return _service;
}

検索が終わったら
- (void)request:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedBase *)aFeed
          error:(NSError *)error {
    if (!error) {
        [self setFeed:(GDataFeedYouTubeVideo *)aFeed];   
        [self.listView reloadData];
    }
}

みたいにして、検索結果をプロパティに設定して、UITableViewを更新する。
タイトル文字列なんかは
    GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
    NSString *title = [[entry title] stringValue];
    NSString *descriotion =
   [[[(GDataEntryYouTubeVideo *)entry mediaGroup]
               mediaDescription] contentStringValue];
    NSArray *thumbnails =
   [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];


こんな感じでとれる。

ここから基本的なコードは取得できる。