iPhone - How to send image + text on facebook using sharekit

As per the requirement in my app I want to send image and text(dynamic-written by user) on the facebook. I have already write the code of sending image which is as follows

NSString *str = [NSString stringWithFormat:@"00%d",currentIndex_+1];

        NSString *imageIndex = [[NSBundle mainBundle] pathForResource:str ofType:@"png"];
        NSLog(@"image index:%@",imageIndex);
       // NSData *myData = [[NSData alloc] initWithContentsOfFile:imageIndex];

            SHKItem *item = [SHKItem image:[UIImage imageWithContentsOfFile:imageIndex] title:@"sent via iphone"];
        [NSClassFromString(@"SHKFacebook") performSelector:@selector(shareItem:) withObject:item];

but now I also want to send text(dynamic) with this image. How can I send text with image?

plz help...

link | improve this question

70% accept rate
 
why don't you use NSString stringWithFormat: i.e.` NSString *var=@"aaa"; SHKItem *item = [SHKItem image:[UIImage imageWithContentsOfFile:imageIndex] title:[NSString stringWithFormat:@"%@ \n%@",var,@"Sent via iSLP Break Roomi iPhone App"]];` –  Michał Zygar  Dec 12 at 11:16
 
but this will be static text I want to send text written by user –  iPhone  Dec 12 at 11:41
 
you can put the text that user had written in NSString *var in my example –  Michał Zygar  Dec 12 at 11:51
feedback

3 Answers

It is very easy. Just make sure to #import the SHKItem and SHKFaceBook

UIImage *image = [UIImage imageNamed:@"someImage.png"];
SHKItem *itemToShare = [SHKItem image:image title:@"Some title if you want to"];
[SHKFacebook shareItem:itemToShare];
link | improve this answer
 
but I want to send dynamic(written by user) text not static –  iPhone  Dec 12 at 11:51
feedback

dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ %@\",\"href\":\"\",\"caption\":\"descriptoin\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://example.com/webservices/images/img.png\",\"href\":\"http://%@/\"}]}",name,msg,url];

replace this code with dialog.attachment which is inside the SHKFacebook.m and replace your image url/path which i am written in bold letter.

and post your text using the code :

SHKItem *item1 =[SHKItem text:@"hello"];

[SHKFacebook shareItem:item1];

link | improve this answer
 
feedback

Call this method to upload with message :

-(void)facebookPhotoUpload {

ShareController *share = [ShareController sharedObject];
share._delegate  = self;
if([share isFacebookLoggedIn]){
    [share fbUploadPicture:ivwCartoon.image withMessage:@"my message"];
}
else {
    share.iSelectedShareOption = fbUploadPicture;
    [share fblogin];
}

}

and ShareViewController.m having below method :

-(void)fbUploadPicture:(UIImage )image withMessage:(NSString)message {

iSelectedShareOption = fbUploadPicture;
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                message, @"message",
                                image, @"source",
                                nil];

[self.facebook requestWithGraphPath:@"me/photos"
                          andParams:params 
                      andHttpMethod:@"POST" 
                        andDelegate:self]; 

}

link | improve this answer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值