ios - 上传 Facebook 照片和自动注销用户(自助服务终端应用程序)
<p><p>我有一个 iPad 应用程序,专为在信息亭环境中使用而设计。 </p>
<p>用户流应该是</p>
<ul>
<li>拍照</li>
<li>从 iPad 相册 View 中选择照片</li>
<li>分享到 Facebook 和/或 Twitter</li>
<li>图片发布后自动注销用户</li>
</ul>
<p>我的 Twitter 自动注销功能正常,我的问题在于 Facebook 部分。</p>
<p>我已经实现了用于内部测试的 Graph API,并且希望能够通过这种方式发布完整的故事,但我认为一旦授权和发布完成,我认为没有办法从 Facebook 应用程序中注销完成。</p>
<p>作为备用方案,我可以使用 Feed Dialog 并从那里自动注销,但据我所知,没有办法从那里上传本 map 片以分享到 Facebook。</p>
<p>我的Facebook分享代码如下:</p>
<pre><code>- (IBAction)facebookShare:(id)sender {
/// Package the image inside a dictionary
NSArray* image = @[@{@"url": self.mergeImages, @"user_generated": @"true"}];
// Create an object
id<FBGraphObject> object =
[FBGraphObject openGraphObjectForPostWithType:@"me/feed:photo"
title:@"a photo"
image:self.mergeImages
url:nil
description:nil];
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>);
// Set image on the action
;
// Link the object to the action
;
// Hardcode the location based on Facebook Place ID
id<FBGraphPlace> place = (id<FBGraphPlace>);
; // Singley + Mackie
;
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionShareDialogParams *params = [ init];
params.action = action;
params.actionType = @"me/feed:share";
// If the Facebook app is installed and we can present the share dialog
if() {
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:@"photo_overlay:share"
previewPropertyName:@"photo"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
// NSLog();
} else {
// Success
NSLog(@"result %@", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
// Put together the Feed dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"name",
@"caption",
@"description",
@"link",
@"picture",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
// NSLog();
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = ];
if (!) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// User clicked the Share button
NSString *result = ];
NSLog(@"result %@", result);
}
}
}
// Auto log the user out
NSUserDefaults *defaults = ;
NSLog(@"defaults fbDidLogout........%@",defaults);
if ()
{
;
;
;
}
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = ;
for (cookie in )
{
NSString* domainName = ;
NSRange domainRange = ;
if(domainRange.length > 0)
{
;
}
}
;
}];
}
}
// A function for parsing URL parameters.
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = ;
NSMutableDictionary *params = [ init];
for (NSString *pair in pairs) {
NSArray *kv = ;
NSString *val =
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params] = val;
}
return params;
}
</code></pre>
<p>我已经在 Stack Overflow 上广泛搜索了这个问题的答案,但没有找到解决方案。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我终于明白了!在这里发布答案,希望对处于相同情况的其他人有所帮助。</p>
<p>首先,将以下内容添加到您的 AppDelegate.m:</p>
<pre><code>-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication fallbackHandler:^(FBAppCall *call) {
// Facebook SDK * App Linking *
// For simplicity, this sample will ignore the link if the session is already
// open but a more advanced app could support features like user switching.
if (call.accessTokenData) {
if (.isOpen) {
NSLog(@"INFO: Ignoring app link because current session is open.");
}
else {
;
}
}
}];
}
// Helper method to wrap logic for handling app links.
- (void)handleAppLink:(FBAccessTokenData *)appLinkToken {
// Initialize a new blank session instance...
FBSession *appLinkSession = [ initWithAppID:nil
permissions:nil
defaultAudience:FBSessionDefaultAudienceNone
urlSchemeSuffix:nil
tokenCacheStrategy: ];
;
// ... and open it from the App Link's Token.
[appLinkSession openFromAccessTokenData:appLinkToken
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
// Forward any errors to the FBLoginView delegate.
if (error) {
//;
}
}];
}
</code></pre>
<p>无论您在应用中的何处调用发布操作,请将此行添加到您的头文件中:</p>
<pre><code>@property (strong, nonatomic) FBRequestConnection *requestConnection;
</code></pre>
<p>以下是你的实现文件:</p>
<pre><code>@synthesize requestConnection;
- (IBAction)facebookShare:(id)sender {
NSArray *permissions = [ initWithObjects:
@"publish_actions", @"publish_checkins", nil];
UIImage *img = self.facebookImage;
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
completionHandler:^(FBSession *session,FBSessionState s, NSError *error) {
;
if (!error) {
// Now have the permission
;
} else {
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
;
}
}
}];
}
-(void)logout {
;
;
;
}
- (void)processPostingImage:(UIImage *) img WithMessage:(NSString *)message {
FBRequestConnection *newConnection = [ init];
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
;
};
FBRequest *request=[ initWithSession:FBSession.activeSession graphPath:@"me/photos" parameters: HTTPMethod:@"POST"];
;
;
self.requestConnection = newConnection;
;
}
// FBSample logic
// Report any results.Invoked once for each request we make.
- (void)requestCompleted:(FBRequestConnection *)connection
forFbID:fbID
result:(id)result
error:(NSError *)error
{
// not the completion we were looking for...
if (self.requestConnection &&
connection != self.requestConnection)
{
return;
}
// clean this up, for posterity
self.requestConnection = nil;
if (error)
{
}
else
{
;
};
}
- (void) presentAlertForError:(NSError *)error {
// Facebook SDK * error handling *
// Error handling is an important part of providing a good user experience.
// When fberrorShouldNotifyUser is YES, a fberrorUserMessage can be
// presented as a user-ready message
if (error.fberrorShouldNotifyUser) {
// The SDK has a message for the user, surface it.
[[ initWithTitle:@"Something Went Wrong"
message:error.fberrorUserMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
} else {
}
}
</code></pre>
<p><strong>注意:</strong>
要使用自动注销功能,您还必须在设备上禁用 Safari。这可以通过转到设置>常规>限制>允许Safari>关闭来完成。一旦关闭,Facebook <code>IBAction</code> 将在应用程序内部弹出一个 <code>UIWebView</code>。点击后,当前用户可以输入他们的 Facebook 凭据,然后该应用将发布图片,然后将用户注销,以便下一个用户可以使用该应用,而无需访问前一个用户的 Facebook 详细信息。</p></p>
<p style="font-size: 20px;">关于ios - 上传 Facebook 照片和自动注销用户(自助服务终端应用程序),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22331275/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22331275/
</a>
</p>
页:
[1]