gpt4 book ai didi

iphone - 使用 UIActivityViewController 感到困惑

转载 作者:行者123 更新时间:2023-12-03 21:02:40 25 4
gpt4 key购买 nike

你能帮我理解什么时候应该使用UIActivityViewController。我有一个按钮,用于共享有关我的应用程序的常见信息(例如带有链接和图像的“我喜欢这个应用程序”)。我的旧代码是:

NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:picture forKey:@"picture"];
[params setObject:link forKey:@"link"];
[params setObject:@"I like MY app!" forKey:@"caption"];
[params setObject:@"I am now using MY iPhone app." forKey:@"description"];
[params setObject:linkToTheIcon forKey:@"icon"];
[params setObject:@"including link" forKey:@"type"];
[[FacebookConnection instance] feedLink:params andDelegate:self];

现在我想使用 UIActivityViewController 但我有点困惑如何将所有这些参数传递给它。或者我应该以其他方式做事?

添加:所以我明白我需要静默发布程序。您能否指导我使用 iOS 6 功能(例如使用内置 FB 帐户)完成静默发布过程。目前我不明白如何检查设备上是否存在FB帐户,如果不存在如何提示创建它? ACAccount存储类中有一个方法 - requestAccessToAccountsWithType:options:completion: 来访问帐户。但如果帐户不存在,则会返回错误。非常感谢。

最佳答案

在您的情况下,很明显您不应该使用 UIActivityViewController 因为您想在 Facebook 上发帖,而不是在 Twitter 或其他任何地方发帖,对吗?首先,您需要访问用户帐户。你这样做:

-(void)requestBasicPermissionsForFacebookAccount {
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = @[@"email"];
NSDictionary * options = @{ACFacebookAppIdKey : kFacebookAppId, ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
FacebookAccountManager * fbMgr = [[FacebookAccountManager alloc] init];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
fbMgr.account = [accounts lastObject];
fbMgr.isBasicPermissionsGranted = YES;
[self.accountManagers addObject:fbMgr];
NSLog(@"granted!");
}
else {
fbMgr.account = nil;
fbMgr.isBasicPermissionsGranted = NO;
switch ([error code]) {
case 1:
[self showErrorAlertWithMessage:@"Unknown error occured, try again later!"];
break;
case 3:
[self showErrorAlertWithMessage:@"Authentication failed, try again later!"];
break;
case 6:
[self showErrorAlertWithMessage:@"Facebook account does not exists. Please create it in Settings and come back!"];
break;
case 7:
[self showErrorAlertWithMessage:@"Permission request failed. You won't be able to share information to Facebook"];
break;
default:
break;
}
NSLog(@"error is: %@", error);
}
}];
}

如果帐户不存在,您应该提示用户在设置中创建它,然后尝试再次获取基本权限。

关于iphone - 使用 UIActivityViewController 感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13432498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com