Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated GoogleAPIClient in tvOS demo #521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion XCDYouTubeKit Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 25 additions & 32 deletions XCDYouTubeKit Demo/tvOS Demo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,52 @@

#import "AppDelegate.h"

#import <GoogleAPIClient/GTLYouTube.h>
#import <GoogleAPIClientForREST/GTLRYouTube.h>

#import "PlaylistCollectionViewController.h"

@interface AppDelegate ()

@property (nonatomic, strong) GTLServiceYouTube *youTubeService;
@property (nonatomic, strong) GTLRYouTubeService *youTubeService;

@end

@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;
}

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import "PlaylistCollectionViewController.h"

#import <AVKit/AVKit.h>
#import <GoogleAPIClient/GTLYouTube.h>
#import <GoogleAPIClientForREST/GTLRYouTube.h>
#import <XCDYouTubeKit/XCDYouTubeKit.h>

#import "VideoCell.h"
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions XCDYouTubeKit Demo/tvOS Demo/VideoCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#import <UIKit/UIKit.h>

#import <GoogleAPIClient/GTLYouTube.h>
#import <GoogleAPIClientForREST/GTLRYouTube.h>

@interface VideoCell : UICollectionViewCell

@property (nonatomic, strong) GTLYouTubePlaylistItem *playlistItem;
@property (nonatomic, strong) GTLRYouTube_PlaylistItem *playlistItem;

@end
8 changes: 5 additions & 3 deletions XCDYouTubeKit Demo/tvOS Demo/VideoCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down