I'm trying to post a message or share a photo in my fb using FacebookSDK. I already follow the steps on how to install it. I'm done applying the login tutorial, but the problem now is how to post a message or share it into my FB using my app. There are a lot of tutorial like this one. I think this is already old for FacebookSDK. Sorry If I'm so noob for this. I know this not the right page to post this, but I don't have any idea now. If you have a tutorial on how to post or share. Please give me link. If ever, can you provide steps for this.
I already try this, but It doesn't post or share.
UPdate
this is my code
import "ShareController.h"
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKMessengerShareKit/FBSDKMessengerShareKit.h>
#implementation ShareController
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://developers.facebook.com"];
FBSDKShareButton *button = [[FBSDKShareButton alloc] init];
button.shareContent = content;
[self.view addSubview:button];
}
- (IBAction)shareButton:(id)sender {
UIImage * image = [UIImage imageNamed:#"sample.png"];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.shareContent= content;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
here's the code for my login. I think this is simple code
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
// Do any additional setup after loading the view, typically from a nib.
}
You did not set permissions, to set the permissions:
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[loginButton logInWithPublishPermissions: #[#"publish_actions"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in");
}
}];
Also it is a good practice to check if user has granted the permission or not in your IBAction method:
- (IBAction)shareButton:(id)sender {
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
// code to share
}
}
Related
I have facebook sharing concept in my app. I need to share the image url, description and when the user click on the image in FB, this will goto website. i used many methods like SLComposeViewController, FBSDKShareLinkContent, FBShareDialogParams.Sometimes these are all working fine. sometimes not working. Now FBShareDialogParams is deprecated in ios 9. Which code is working fine in ios9. Is any one know???
Try This Code:-
FBSDKShareLinkContent *sharecontent = [[FBSDKShareLinkContent alloc]init];
sharecontent.contentTitle = #"Hello ... My Dear Friends";
sharecontent.contentDescription =#"share this images";
sharecontent.imageURL = [NSURL URLWithString:#"http://www.picgifs.com/glitter-gifs/c/congratulations/picgifs-congratulations-178787.gif"];
sharecontent.contentURL = [NSURL URLWithString:#"https://itunes.apple.com"];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
dialog.shareContent = sharecontent;
[dialog show];
// PRAGMA :- Delegate Method
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"Finished");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
}
Please excuse the elementary question but I am pretty confused on requesting Facebook permissions for my app. My app allows users to select photos then login to their facebook page and those photos are posted on their timeline. I am requesting manage_pages, publish_pages, and publish_actions. In my developer account I added two testers who are friends of mine and we thoroughly tested the process. Everything works perfectly. But when I created a Test User (the one where facebook creates a generic account) my app doesn't post photos to their wall. I granted the test user the same permissions. I am now wondering if I need to call user_photos as another requested permission. I don't think I do since I am not requesting access to the users photos or albums. I am simply posting photos to their timeline which I thought is what publish_pages and publish_actions does. Can you look at the code and see if you can find what I am doing wrong?
- (IBAction)facebookButtonClicked1:(id)sender
{
if ([self.selectedImages count] > 0)
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[login logInWithPublishPermissions:#[#"publish_actions"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in");
[self shareSegmentWithFacebookComposer];
}
}];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Photos" message:#"You have not selected any photo." delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
}
-(void)shareSegmentWithFacebookComposer{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[self publishFBPost]; //publish
} else {
NSLog(#"no publish permissions");
}
}
-(void) publishFBPost{
NSMutableArray* photos = [[NSMutableArray alloc] init];
for (NSString* imageFile in self.selectedImages) {
UIImage *image = [UIImage imageWithContentsOfFile:[dataPath stringByAppendingPathComponent:imageFile]];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;
[photos addObject:photo];
}
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = [photos copy];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
[FBSDKShareAPI shareWithContent:content delegate:nil];
viewThanks.hidden = NO;
[NSTimer scheduledTimerWithTimeInterval:4.5 target:self selector:#selector(start) userInfo:nil repeats:NO];
FBSDKShareDialog *shareDialog = [FBSDKShareDialog new];
[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog show];
}
There were publish_stream permission to upload photos but in the latest SDK publish_actions have replaced publish_actions so you only need publish_actions. And if you want to see the user's photos then you need the user_photos permission.
using a simple UIActivityViewController
-(void)share{
NSString *textToShare = _mytext;
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
UIImage *imageToShare = _myimage;
NSArray *activityItems = #[textToShare, url, imageToShare];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
I want to share a text, url and image where appropriate.
So if the user chooses mail, everything appears. Etc with the rest of the apps (pinterest, facebook, twitter)
On Facebook Messenger - If a url and an image is shared, the share screen crashes. Is this a known issue (can't send image with a url)?
* EDIT: Updated to the latest SDK
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = #"Your title";
content.contentDescription = #"Some description text maybe...";
content.contentURL = [NSURL URLWithString:#"http://yourlink.com"];
content.imageURL = [NSURL URLWithString:#"http://yourlink.com/theImage.png"];
[FBSDKMessageDialog showWithContent:content delegate:self];
// Delegate
- (void)sharer: (id<FBSDKSharing>)sharer didCompleteWithResults: (NSDictionary *)results
{
BOOL complete = [[results valueForKeyPath:#"didComplete"] boolValue];
NSString *completionGesture = [results valueForKeyPath:#"completionGesture"];
if (completionGesture && [completionGesture isEqualToString:#"cancel"]) {
// action was canceled by the user
}
if (complete) {
// the message/link/image was sent
}
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
// handle error...
}
You can give it a try :)
Could any one please help me with this code i'm trying to call alertview indicator before pulling json data in my iOS app but i don't know how to check if the data already loaded and then disappear the alertview indicator, For now it always appears even all data aleady loaded. here is my code:
//
// Firstcine.m
//
//
//
//
#import "Firstcine.h"
#interface Firstcine (){
UIAlertView *loading;
}
#end
#implementation Firstcine
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Loading Show Alert View...
loading = [[UIAlertView alloc] initWithTitle:#"" message:#"Please Wait..."
delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView
alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loading addSubview:progress];
[progress startAnimating];
[loading show];
// dis play all data after first loaded
NSURL *url = [NSURL URLWithString:#"http://localhost/App/first.php"];
NSData *jsonData = [NSData dataWithContentsOfURL:url];
NSArray *json = [NSJSONSerialization JSONObjectWithData:
jsonData options:NSJSONReadingAllowFragments error:nil];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_tile.png"]];
NSDictionary *dict = [json objectAtIndex:0];
name.text = [dict valueForKey:#"name"];
time.text = [dict valueForKey:#"time"];
date.text = [dict valueForKey:#"date"];
price.text = [dict valueForKey:#"price"];
// then display photo
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(75, 87, 150,200)];
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[dict valueForKey:#"photo" ]]]];
[self.view addSubview:image];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Have you tried something like this
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Configuring Preferences\nPlease Wait..."
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alertView show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alertView.bounds.size.width / 2, alertView.bounds.size.height - 50);
[indicator startAnimating];
[alertView addSubview:indicator];
dispatch_queue_t downloadQueue = dispatch_queue_create("saver", NULL);
dispatch_async(downloadQueue, ^{
// do some heavy lifting ? like a fetch
dispatch_async(dispatch_get_main_queue(), ^{
// hide the view
[alertView dismissWithClickedButtonIndex:0 animated:YES];
});
});
I want to put a custom button on the top of SKStoreProductViewController. I tried it like below but it did not work. I was wondering if you could give me any advices.
SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(showShareDialog)];
storeViewController.navigationItem.rightBarButtonItem = shareButton;
storeViewController.delegate = self;
[self presentViewController:storeViewController animated:YES completion:^() {
[storeViewController loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier:appId}
completionBlock:^(BOOL result, NSError *error) {}];
}];