I’m trying to adapt the original Sharekit demo app so that it allows me to authenticate dropbox on a single button press (instead of appearing a new view etc. like it does in the demo).
To do this I have wired up a button with the following method as the IBAction (in the initial ViewController it launches into on Storyboard):
-(IBAction)assignDropbox:(id)sender
{
[SHK setRootViewController:self];
Class sharerClass = NSClassFromString(@"SHKDropbox");
BOOL isiOSSharer = [sharerClass isSubclassOfClass:[SHKiOSSharer class]];
if ([sharerClass isServiceAuthorized]) {
if (isiOSSharer) {
[sharerClass getUserInfo];
UIAlertView *iosSharerAlert = [[UIAlertView alloc] initWithTitle:@"iOS Social.framework sharer"
message:@"You can deauthorize this kind of sharer in settings.app, not here. By tapping this button you have refetched user info data only."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[iosSharerAlert show];
} else {
[sharerClass logout];
//[self.tableView reloadData];
}
} else {
SHKSharer *sharer = [[sharerClass alloc] init];
[sharer authorize];
if (isiOSSharer) {
UIAlertView *iosSharerAlert = [[UIAlertView alloc] initWithTitle:@"iOS Social.framework sharer"
message:@"You can authorize this kind of sharer in settings.app, not here."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[iosSharerAlert show];
}
}
if ([sharerClass isServiceAuthorized]) {
NSLog(@"After Logging in Username: %@", [sharerClass username]);
} else {
NSLog(@"After Logging in Username: %@", [sharerClass username]);
}
}
I’ve added the following notification code ViewDidLoad of the ViewController:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(authDidFinish:)
name:@"SHKAuthDidFinish"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendDidCancel:)
name:@"SHKSendDidCancel"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendDidStart:)
name:@"SHKSendDidStartNotification"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendDidFinish:)
name:@"SHKSendDidFinish"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendDidFailWithError:)
name:@"SHKSendDidFailWithError"
object:nil];
With the following code within the actual main (to make the notifications actually work - as per setup):
- (void)authDidFinish:(NSNotification*)notification
{
NSDictionary *userInfo = notification.userInfo;
NSNumber *success = [userInfo objectForKey:@"success"];
if (NO == [success boolValue]) {
NSLog(@"authDidFinish: NO");
} else {
NSLog(@"authDidFinish: YES");
NSLog(@"userInfo: %@", userInfo);
}
}
- (void)sendDidCancel:(NSNotification*)notification
{
NSLog(@"sendDidCancel:");
}
- (void)sendDidStart:(NSNotification*)notification
{
NSLog(@"sendDidStart:");
}
- (void)sendDidFinish:(NSNotification*)notification
{
NSLog(@"sendDidFinish:");
}
- (void)sendDidFailWithError:(NSNotification*)notification
{
NSLog(@"sendDidFailWithError:");
}'
It launches the web view in the app, and I can authenticate (I get notifications from dropbox saying another device has logged on), however the save authentication/session code in ‘SHKDropbox.m’ is never called. Method under:
- (void)restClient:(DBRestClient*)client loadedAccountInfo:(DBAccountInfo*)info
I’ve done a lot of comparison work to see what the differences are between the projects, but can’t see any difference in settings. Have you got any storyboard/button presses sample code as described above. Or have you got any idea on why this isn’t working on ShareKit?