Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Invalid JSON fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johan committed Aug 9, 2013
1 parent 0adb060 commit d7d58a2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Traktable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
"$(inherited)",
"\"$(SRCROOT)/Traktable\"",
);
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = Traktable;
WRAPPER_EXTENSION = app;
};
Expand All @@ -685,7 +685,7 @@
"$(inherited)",
"\"$(SRCROOT)/Traktable\"",
);
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = Traktable;
WRAPPER_EXTENSION = app;
};
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Traktable/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
_video = [[ITVideo alloc] init];
_library = [[ITLibrary alloc] init];

if(![self.api testAccount]) {
if(![self.api username] || ![self.api testAccount]) {

[self noAuthAlert];
[self displayPreferences:self];
Expand Down
24 changes: 20 additions & 4 deletions Traktable/ITApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,17 @@ - (NSDictionary *)callURLSync:(NSString *)requestUrl withParameters:(NSDictionar

NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];

NSDictionary *responseDict = [[SBJsonParser alloc] objectWithData:data];

id responseDict = nil;

responseDict = [[SBJsonParser alloc] objectWithData:data];

Class hasNSJSON = NSClassFromString(@"NSJSONSerialization");

if(hasNSJSON != nil) {
responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
}

return responseDict;
}

Expand Down Expand Up @@ -217,7 +225,15 @@ - (void)callURL:(NSString *)requestUrl withParameters:(NSDictionary *)params com
return;
}

NSDictionary *responseDict = [[SBJsonParser alloc] objectWithData:data];
id responseDict = nil;

responseDict = [[SBJsonParser alloc] objectWithData:data];

Class hasNSJSON = NSClassFromString(@"NSJSONSerialization");

if(hasNSJSON != nil) {
responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
}

completionBlock(responseDict, nil);
});
Expand Down Expand Up @@ -251,7 +267,7 @@ - (BOOL)testAccount {

NSString *url = [NSString stringWithFormat:@"%@/account/test/%@", kApiUrl, [self apiKey]];
NSDictionary *data = [self callURLSync:url withParameters:params];

NSLog(@"%@",data);
if([[data objectForKey:@"status"] isEqualToString:@"failure"])
return NO;
else
Expand Down
3 changes: 1 addition & 2 deletions Traktable/ITLibrary.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ @implementation ITLibrary
- (id)init {

iTunesBridge = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
ITApi *api = [ITApi new];

NSString *appSupportPath = [ITLibrary applicationSupportFolder];
[self createDir:appSupportPath];
Expand All @@ -41,7 +40,7 @@ - (id)init {

bool b = [self dbExists];

if([api testAccount] && b == NO) {
if(b == NO) {

[self resetDb];
}
Expand Down

0 comments on commit d7d58a2

Please sign in to comment.