1

Archive Project

This commit is contained in:
Kim Wittenburg
2017-07-25 17:21:13 +02:00
parent 7d4f001502
commit 15062dfb27
66 changed files with 14172 additions and 4692 deletions

View File

@@ -0,0 +1,52 @@
//
// NYTUtil.m
// Notifications for YouTube
//
// Created by Kim Wittenburg on 21.07.13.
// Copyright (c) 2013 Kim Wittenburg. All rights reserved.
//
#import "NYTUtil.h"
// API Imports
#import "GTMOAuth2Authentication.h"
// Core Imports
#import "NYTAuthentication.h"
extern NSXMLDocument * LoadXMLDocumentSynchronous(NSString *url, GTMOAuth2Authentication *auth, NSError **outError)
{
// Group to wait for refresh of token (if neccessary)
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
// Create the request; authenticate and authorize it.
NSURL *actualURL = [NSURL URLWithString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:actualURL];
[request setValue:DeveloperKey forHTTPHeaderField:DeveloperKeyHTTPHeaderField];
dispatch_sync(dispatch_get_main_queue(), ^{
// Seems that authorization must be performed on the main queue
[auth authorizeRequest:request completionHandler:^(NSError *error) {
if (outError != NULL) {
*outError = error;
}
dispatch_group_leave(group);
}];
});
// Wait for authorization
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
if (*outError) {
// The authorization failed
return nil;
}
// Create the document
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:outError];
if (!data) {
return nil;
}
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data options:NSXMLDocumentTidyXML error:outError];
return document;
}