ios - iOS6 social framework bring up No Account Alert -
similar ios 6 social framework not going settings or no alert trying use slrequest:
i trying bring alert "no facebook account" when user has not logged in facebook in settings. have found alert appear after present slcomposeviewcontroller, rather inside if statement.
if([slcomposeviewcontroller isavailableforservicetype:slservicetypefacebook]) { slcomposeviewcontroller *controller = [slcomposeviewcontroller composeviewcontrollerforservicetype:slservicetypefacebook]; //setup controller , callback code [self presentviewcontroller:controller animated:yes completion:nil]; }
however, trying use slrequest , dont want present slcomposeviewcontroller, instead, after checking accounts, popup alert. code here:
- (void)postimagefb { if([slcomposeviewcontroller isavailableforservicetype:slservicetypefacebook]) { nslog(@"can post"); } else { nslog(@"cant post"); } acaccountstore *accountstore = [[acaccountstore alloc] init]; acaccounttype *accounttype = [accountstore accounttypewithaccounttypeidentifier:acaccounttypeidentifierfacebook]; nsarray *accountsarray = [accountstore accountswithaccounttype:accounttype]; nslog(@"accounts: %i", [accountsarray count]); // possible popup alert here if accounts = 0? nsdictionary *options = @{ acfacebookappidkey: @"123456789", acfacebookpermissionskey: @[@"publish_stream"], acfacebookaudiencekey: acfacebookaudiencefriends }; [accountstore requestaccesstoaccountswithtype:accounttype options:options completion:^(bool granted, nserror *error) { if(granted) { nsarray *accountsarray = [accountstore accountswithaccounttype:accounttype]; if ([accountsarray count] > 0) { acaccount *facebookaccount = [accountsarray objectatindex:0]; nsdictionary *parameters = @{@"message": @"testing"}; slrequest *facebookrequest = [slrequest requestforservicetype:slservicetypefacebook requestmethod:slrequestmethodpost url:[nsurl urlwithstring:@"https://graph.facebook.com/me/photos"] parameters:parameters]; [facebookrequest addmultipartdata: [self getimagedatafromplistwithfilename:@"image1.png"] withname:@"source" type:@"multipart/form-data" filename:@"testimage"]; facebookrequest.account = facebookaccount; [facebookrequest performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) { if (error) { nslog(@"%@",error.description); } else { nslog(@"responedata:%@", [[nsstring alloc] initwithdata:responsedata encoding:nsutf8stringencoding]); } }]; } } }]; }
ok, have discovered isavailableforservicetype returns true? started testing on device.
i figured using invisible slcomposeviewcontroller bring alert seems suitable workaround:
if (![slcomposeviewcontroller isavailableforservicetype:slservicetypefacebook]) { slcomposeviewcontroller *controller = [slcomposeviewcontroller composeviewcontrollerforservicetype:slservicetypefacebook]; controller.view.hidden = yes; [self presentviewcontroller:controller animated:no completion:nil]; } else { // put posting code here: slcomposeviewcontroller or slrequest }
Comments
Post a Comment