简体   繁体   中英

Use Facebook SDK session object with the UIActivityViewController on iOS

I'm using the Facebook SDK on iOS to sign in users in my app. After the user logs in, I have the FBSession object available to share and make other requests to the Facebook API.

I have a feature in which the user has the option to share some specific content through the available social services, so I decided to use the UIActivityViewController to accomplish this.

My question is: Is there a way to use the FBSession from the logged in user to select the Facebook option on the UIActivityViewController without having to log in again on the device settings? Thanks!

If you've used the system Facebook to login, if you provide items to UIActivityController that Facebook can process (such as text and an image, either or), it should automatically show up in the available sharing methods once opened.

UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[text, url, image] applicationActivities:nil];

[self presentViewController:controller animated:YES completion:nil];

If you don't want to use the system Facebook login, you're going to have to create your own UIActivity , which will use the FBSession object you refer to. Then pass your custom UIActivity object into the applicationActivities parameter when initialising your UIActivityViewController .

Check out the UIActivity Documentation . It'll tell you everything you need to know in order to implement a custom activity using the existing FBSession object.

I'd advise using the system Facebook functionality where possible, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM