Created
February 4, 2013 16:08
-
-
Save clooth/4707704 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Avian.h | |
// Avian | |
// | |
// Created by Nico Hämäläinen on 2/4/13. | |
// Copyright (c) 2013 Nico Hämäläinen. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <Accounts/Accounts.h> | |
#import <Social/Social.h> | |
@interface Avian : NSObject { | |
NSArray* accounts; | |
} | |
- (void) loadAccounts; | |
- (NSArray*) accounts; | |
- (void) setAccounts: (NSArray*)newAccounts; | |
@end | |
// | |
// Avian.m | |
// Avian | |
// | |
// Created by Nico Hämäläinen on 2/4/13. | |
// Copyright (c) 2013 Nico Hämäläinen. All rights reserved. | |
// | |
#import "Avian.h" | |
#import <Foundation/Foundation.h> | |
#import <Accounts/Accounts.h> | |
#import <Social/Social.h> | |
@implementation Avian | |
- (id) init | |
{ | |
if ( self = [super init] ) | |
{ | |
[self loadAccounts]; | |
} | |
return self; | |
} | |
- (void) loadAccounts { | |
// Initialize account store | |
ACAccountStore *account = [[ACAccountStore alloc] init]; | |
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; | |
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { | |
// Did the user allow us access or have any accounts? | |
if (granted) { | |
NSArray *twitterAccounts = [account accountsWithAccountType:accountType]; | |
// Sanity check | |
if ([twitterAccounts count] > 0) { | |
[self setAccounts:twitterAccounts]; | |
} | |
else { | |
NSLog(@"No Twitter accounts found."); | |
} | |
} | |
else { | |
NSLog(@"No access granted because: %@", [error localizedDescription]); | |
} | |
}]; | |
} | |
- (NSArray*) accounts { | |
return accounts; | |
} | |
- (void) setAccounts:(NSArray *)newAccounts { | |
self.accounts = newAccounts; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment