diff --git a/XCDYouTubeKit Demo/Podfile b/XCDYouTubeKit Demo/Podfile index 7ce89874..a3f2b3da 100644 --- a/XCDYouTubeKit Demo/Podfile +++ b/XCDYouTubeKit Demo/Podfile @@ -19,5 +19,5 @@ end target 'XCDYouTubeKit tvOS Demo' do platform :tvos, '9.0' - pod 'GoogleAPIClient/YouTube', '~> 1.0' + pod 'GoogleAPIClientForREST/YouTube', '~> 1.5' end diff --git a/XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m b/XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m index b7266fe0..63fa718a 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m +++ b/XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m @@ -4,13 +4,13 @@ #import "AppDelegate.h" -#import +#import #import "PlaylistCollectionViewController.h" @interface AppDelegate () -@property (nonatomic, strong) GTLServiceYouTube *youTubeService; +@property (nonatomic, strong) GTLRYouTubeService *youTubeService; @end @@ -18,18 +18,16 @@ @implementation AppDelegate @synthesize window = _window; -- (GTLServiceYouTube *) youTubeService +- (GTLRYouTubeService *) youTubeService { - if (!_youTubeService) - { - _youTubeService = [GTLServiceYouTube new]; - _youTubeService.shouldFetchNextPages = YES; - _youTubeService.retryEnabled = YES; - // Please enter your YouTube API Key in `XCDYouTubeKit Demo/tvOS Demo/Supporting Files/YouTube-API-Key.plist` - NSData *youTubeAPIKeyData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"YouTube-API-Key" withExtension:@"plist"]]; - _youTubeService.APIKey = [NSPropertyListSerialization propertyListWithData:youTubeAPIKeyData options:NSPropertyListImmutable format:NULL error:NULL]; - NSAssert(_youTubeService.APIKey.length > 0, @"An API key is required, see https://developers.google.com/youtube/v3/getting-started"); - } + GTLRYouTubeService *_youTubeService = [[GTLRYouTubeService alloc] init]; + _youTubeService.shouldFetchNextPages = YES; + _youTubeService.retryEnabled = YES; + // Please enter your YouTube API Key in `XCDYouTubeKit Demo/tvOS Demo/Supporting Files/YouTube-API-Key.plist` + NSData *youTubeAPIKeyData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"YouTube-API-Key" withExtension:@"plist"]]; + _youTubeService.APIKey = [NSPropertyListSerialization propertyListWithData:youTubeAPIKeyData options:NSPropertyListImmutable format:NULL error:NULL]; + NSAssert(_youTubeService.APIKey.length > 0, @"An API key is required, see https://developers.google.com/youtube/v3/getting-started"); + return _youTubeService; } @@ -37,26 +35,21 @@ - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions: { UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; PlaylistCollectionViewController *playlistCollectionViewController = (PlaylistCollectionViewController *)navigationController.viewControllers[0]; - - GTLQueryYouTube *playlistQuery = [GTLQueryYouTube queryForPlaylistsListWithPart:@"snippet"]; - playlistQuery.identifier = @"PLivjPDlt6ApTA612eSR6Y7vrNys2hBKIr"; - - GTLQueryYouTube *playlistItemsQuery = [GTLQueryYouTube queryForPlaylistItemsListWithPart:@"snippet"]; - playlistItemsQuery.playlistId = playlistQuery.identifier; + + GTLRYouTubeQuery_PlaylistItemsList *playlistItemsQuery = [GTLRYouTubeQuery_PlaylistItemsList queryWithPart:@[@"snippet"]]; + playlistItemsQuery.playlistId = @"PLivjPDlt6ApTA612eSR6Y7vrNys2hBKIr"; playlistItemsQuery.maxResults = 50; - - [self.youTubeService executeQuery:playlistQuery completionHandler:^(GTLServiceTicket *ticket, GTLYouTubePlaylistListResponse *response, NSError *error) { - if (response) - playlistCollectionViewController.title = ((GTLYouTubePlaylist *)response.items.firstObject).snippet.title; - else - NSLog(@"Playlist Query Error: %@", error); - }]; - - [self.youTubeService executeQuery:playlistItemsQuery completionHandler:^(GTLServiceTicket *ticket, GTLYouTubePlaylistItemListResponse *response, NSError *error) { - if (response) - playlistCollectionViewController.items = response.items; - else - NSLog(@"PlaylistItems Query Error: %@", error); + + [self.youTubeService executeQuery:playlistItemsQuery + completionHandler:^(GTLRServiceTicket *callbackTicket, + GTLRYouTube_PlaylistItemListResponse *playlistItemList, + NSError *callbackError) { + if (callbackError != nil) { + NSLog(@"Fetch failed: %@", callbackError); + } else { + playlistCollectionViewController.title = playlistItemList.items[0].snippet.title; + playlistCollectionViewController.items = playlistItemList.items; + } }]; return YES; diff --git a/XCDYouTubeKit Demo/tvOS Demo/PlaylistCollectionViewController.m b/XCDYouTubeKit Demo/tvOS Demo/PlaylistCollectionViewController.m index 9ca35de1..4e2e626a 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/PlaylistCollectionViewController.m +++ b/XCDYouTubeKit Demo/tvOS Demo/PlaylistCollectionViewController.m @@ -5,7 +5,7 @@ #import "PlaylistCollectionViewController.h" #import -#import +#import #import #import "VideoCell.h" @@ -65,7 +65,7 @@ - (void) collectionView:(UICollectionView *)collectionView willDisplayCell:(Vide - (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath; { - GTLYouTubePlaylistItem *playlistItem = self.items[indexPath.row]; + GTLRYouTube_PlaylistItem *playlistItem = self.items[indexPath.row]; AVPlayerViewController *playerViewController = [AVPlayerViewController new]; [self presentViewController:playerViewController animated:YES completion:nil]; diff --git a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.h b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.h index 2b0be990..9f6fd6e1 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.h +++ b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.h @@ -4,10 +4,10 @@ #import -#import +#import @interface VideoCell : UICollectionViewCell -@property (nonatomic, strong) GTLYouTubePlaylistItem *playlistItem; +@property (nonatomic, strong) GTLRYouTube_PlaylistItem *playlistItem; @end diff --git a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m index 080ef049..6d948174 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m +++ b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m @@ -21,15 +21,17 @@ - (void) prepareForReuse [self.imageDataTask cancel]; } -- (void) setPlaylistItem:(GTLYouTubePlaylistItem *)playlistItem +- (void) setPlaylistItem:(GTLRYouTube_PlaylistItem *)playlistItem { _playlistItem = playlistItem; self.titleLabel.text = playlistItem.snippet.title; + self.titleLabel.textColor = [UIColor blackColor]; - GTLYouTubeThumbnailDetails *thumbnails = playlistItem.snippet.thumbnails; - GTLYouTubeThumbnail *thumbnail = thumbnails.maxres ?: thumbnails.high ?: thumbnails.medium ?: thumbnails.standard; + GTLRYouTube_ThumbnailDetails *thumbnails = playlistItem.snippet.thumbnails; + GTLRYouTube_Thumbnail *thumbnail = thumbnails.maxres ?: thumbnails.high ?: thumbnails.medium ?: thumbnails.standard; NSURL *thumbnailURL = [NSURL URLWithString:thumbnail.url]; + self.imageDataTask = [[NSURLSession sharedSession] dataTaskWithURL:thumbnailURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ self.imageView.image = self.playlistItem == playlistItem ? [UIImage imageWithData:data] : nil;