Hi I am new in development of iOS. I make class named socialClass.h
#import <Social/Social.h>
#import <Accounts/Accounts.h>
- (void)facebookSharingStatusCheckCall:(NSString *)url image:(NSString *)img status:(NSString *)text viewCont:(UIViewController *)uiVew;
- (void)facebookForIosSix:(NSString *)url image:(NSString *)img status:(NSString *)text viewCont:(UIViewController *)uiVew;
and in socialClass.m
- (void)facebookSharingStatusCheckCall:(NSString *)url image:(NSString *)img status:(NSString *)text viewCont:(UIViewController *)uiVew
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
NSLog(@"service available");
[self facebookForIosSix:url image:img status:text viewCont:uiVew];
} else {
// facebook for iOS 5 function will be called here
}
}
-(void)facebookForIosSix:(NSString *)url image:(NSString *)img status:(NSString *)text viewCont:(UIViewController *)uiVew
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbcontroller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Post Cancelled");
} else
{
NSLog(@"Post Done");
}
[fbcontroller dismissViewControllerAnimated:YES completion:Nil];
};
fbcontroller.completionHandler =myBlock;
//Adding the Text to the facebook post value from iOS
[fbcontroller setInitialText:text];
//Adding the URL to the facebook post value from iOS
[fbcontroller addURL:[NSURL URLWithString:url]];
//Adding the Image to the facebook post value from iOS
[fbcontroller addImage:[UIImage imageNamed:img]];
[uiVew presentViewController:fbcontroller animated:YES completion:nil];
}
else{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"You can't Post a Status right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
NSLog(@"UnAvailable");
}
}
Now I call in mainViewController.h
#import "socialClass.h"
and in mainViewController.m
- (IBAction)facebookShareBtn:(id)sender {
[[socialClass facebookSharingStatusCheckCall:[[DataPassing sharedManager] pageURL ]
image:[[DataPassing sharedManager]
pageIMGurl]
status:[[DataPassing sharedManager] pageTEXT]]
viewCont:(UIViewController*)self];
}
When I use this below code with self it gives error. Definitely because there is no self view
[self presentViewController:fbcontroller animated:YES completion:nil]; so i put uiView in function and try to pass self from mainViewController. again error in mainview
How can I use this facebook from other calls function in mainviewcontroller. thx
[EDIT]
i declare socialClass.h in mainViewController and call the function in button [socialClass facebookForIosSix:...]
This error is comming... after updating to (UIViewController*)self