0
類似iOS 6 Social framework not going to settings or no alert但我試圖用SLRequest:iOS6的社會結構帶來了無帳戶警報
我試圖彈出警告「沒有Facebook的帳戶」當用戶沒有登錄到Facebook在設置。我發現警報在出現SLComposeViewController之後出現,而不是出現在if語句中。
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//setup controller and callback code
[self presentViewController:controller animated:YES completion:nil];
}
不過,我試圖用SLRequest,我不希望出現的SLComposeViewController,而是清查賬目後,彈出警報。我的代碼是在這裏:
- (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]);
// Is it possible to popup the 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]);
}
}];
}
}
}];
}
然而,這顯示鍵盤,其中是不恰當的背景 – 2013-10-30 07:28:18