我正在将 Facebook 集成到我的应用程序中,以便将视频上传到 FB。一切正常。
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
__block ACAccount *facebookAccount;
NSDictionary *options = @{
ACFacebookAppIdKey: @"457887770928321",
ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
facebookAccount = [accountsArray objectAtIndex:0];
NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"thaiPhuketKaronBeach" ofType:@"MOV"];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *params = @{
@"title": @"A video post",
@"description": @"Me testing the video upload to Facebook."
};
SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:videourl
parameters:params];
[uploadRequest addMultipartData:videoData
withName:@"source"
type:@"video/quicktime"
filename:[pathURL absoluteString]];
uploadRequest.account = facebookAccount;
NSLog(@"Uploading...");
[uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if(error){
NSLog(@"Error %@", error.localizedDescription);
}else
NSLog(@"Success : %@", responseString);
}];
}
else{
// I want to redirect from here to settings app
}
}
}];
如果出现以下情况,我如何重定向到设置应用程序来配置 FB 登录accountsArray count == 0
?