From 638dbe4a6efe4da0d9a0246db4ae56bcdc4c7b39 Mon Sep 17 00:00:00 2001 From: Dave Nicolson Date: Sun, 14 Feb 2021 02:20:24 +0100 Subject: [PATCH 1/2] Replace deprecated GoogleAPIClient --- XCDYouTubeKit Demo/Podfile | 2 +- XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m | 57 ++++++++----------- .../PlaylistCollectionViewController.m | 4 +- XCDYouTubeKit Demo/tvOS Demo/VideoCell.h | 4 +- XCDYouTubeKit Demo/tvOS Demo/VideoCell.m | 7 ++- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/XCDYouTubeKit Demo/Podfile b/XCDYouTubeKit Demo/Podfile index 7ce898741..a3f2b3da6 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 b7266fe08..63fa718a9 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 9ca35de1f..4e2e626a5 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 2b0be9902..9f6fd6e14 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 080ef0491..3d4c8a6da 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m +++ b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m @@ -21,15 +21,16 @@ - (void) prepareForReuse [self.imageDataTask cancel]; } -- (void) setPlaylistItem:(GTLYouTubePlaylistItem *)playlistItem +- (void) setPlaylistItem:(GTLRYouTube_PlaylistItem *)playlistItem { _playlistItem = playlistItem; self.titleLabel.text = playlistItem.snippet.title; - 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; From f93f56a95c2a3fb8b5ccf666c55e0f3cc80f9cf5 Mon Sep 17 00:00:00 2001 From: Dave Nicolson Date: Sun, 14 Feb 2021 02:32:00 +0100 Subject: [PATCH 2/2] Set initial label color for videos --- XCDYouTubeKit Demo/tvOS Demo/VideoCell.m | 1 + 1 file changed, 1 insertion(+) diff --git a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m index 3d4c8a6da..6d948174f 100644 --- a/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m +++ b/XCDYouTubeKit Demo/tvOS Demo/VideoCell.m @@ -26,6 +26,7 @@ - (void) setPlaylistItem:(GTLRYouTube_PlaylistItem *)playlistItem _playlistItem = playlistItem; self.titleLabel.text = playlistItem.snippet.title; + self.titleLabel.textColor = [UIColor blackColor]; GTLRYouTube_ThumbnailDetails *thumbnails = playlistItem.snippet.thumbnails; GTLRYouTube_Thumbnail *thumbnail = thumbnails.maxres ?: thumbnails.high ?: thumbnails.medium ?: thumbnails.standard;