From 85e2f200fb72cde98e5e49fa88b65f675ccdec2e Mon Sep 17 00:00:00 2001 From: Ignacio Romero Date: Sun, 13 Oct 2013 22:25:46 -0300 Subject: [PATCH] Added setClientId:clientSecret:andClientCallbackURL: method for initialization without a plist file --- NRGramKit/NRGramKit.h | 2 ++ NRGramKit/NRGramKit.m | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NRGramKit/NRGramKit.h b/NRGramKit/NRGramKit.h index 34c7f84..75f1a46 100644 --- a/NRGramKit/NRGramKit.h +++ b/NRGramKit/NRGramKit.h @@ -63,6 +63,8 @@ typedef void(^RelationshipResultBlock)(IGIncomingRelationshipStatus,IGOutgoingRe @interface NRGramKit : NSObject { } ++(void)setClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret andClientCallbackURL:(NSString *)callbackURL; + +(BOOL) isLoggedIn; +(IGUser*) loggedInUser; +(void)loginInWebView:(UIWebView*)webview loginLoadingCallback:(LoginLoadingBlock)loadingCallback finishedCallback:(LoginResultBlock)callback; diff --git a/NRGramKit/NRGramKit.m b/NRGramKit/NRGramKit.m index a221921..0b7173e 100644 --- a/NRGramKit/NRGramKit.m +++ b/NRGramKit/NRGramKit.m @@ -27,14 +27,32 @@ +(void)initialize { access_token = [[NSUserDefaults standardUserDefaults] objectForKey:kAccessTokenKey]; - NSBundle *bundle = [NSBundle mainBundle]; - //NSLog(bundle); - NSString *path = [bundle pathForResource:@"NRGramKitConfigs" ofType:@"plist"]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"NRGramKitConfigs" ofType:@"plist"]; NSDictionary* configs = [[NSDictionary alloc]initWithContentsOfFile:path]; callback_url = configs[@"InstagramClientCallbackURL"]; client_id = configs[@"InstagramClientId"]; } ++(void)setClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret andClientCallbackURL:(NSString *)callbackURL +{ + NSString* path = [[NSBundle mainBundle] pathForResource:@"NRGramKitConfigs" ofType:@"plist"]; + NSMutableDictionary* configs = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; + + if (clientId) { + client_id = clientId; + [configs setObject:clientId forKey:@"InstagramClientId"]; + } + if (clientSecret) { + [configs setObject:clientSecret forKey:@"InstagramClientSecret"]; + } + if (callbackURL) { + callback_url = callbackURL; + [configs setObject:callbackURL forKey:@"InstagramClientCallbackURL"]; + } + + [configs writeToFile:path atomically:YES]; +} + +(void)setAccessToken:(NSString*)accessToken; { if(accessToken!=nil)