In my project i am having 5 levels. In First and second level i can able to move and shoot at a time. When completing 2nd level i want to share it with Facebook. After facebook share i cant able to move and shoot at a time. Only one process is working(Either shoot or move).
What i want to do for solve this problem.
My coding is here:
{
UIViewController*v=[[UIViewController alloc]init];
[[[CCDirector sharedDirector]openGLView]addSubview:v.view];
SLComposeViewController*mySLComposerSheet;
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
NSString *strg=[NSString stringWithFormat:#" "];
NSString *bodyStr=[NSString stringWithFormat:#"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"!\n;
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter
[mySLComposerSheet setInitialText:bodyStr]; //the message you want to post
[mySLComposerSheet addImage:[UIImage imageNamed:#"my.jpg"]]; //an image you could post
NSURL *url = [NSURL URLWithString:#"https:example.com"];
[mySLComposerSheet addURL:url];
[v presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output,*head;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"FREE levels NOT unlocked";
head=#"Facebook Share Unsuccessfull";
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:head message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert1 show];
[self reload];
break;
case SLComposeViewControllerResultDone:
output = #"Extra FREE levels successfully unlocked";
head=#"Successfull";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:head message:output delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
alert.tag=22;
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
}
You are presenting the ViewController mySLComposerSheet
[v presentViewController:mySLComposerSheet animated:YES completion:nil];
but there is no dismiss... statement in your completionHandler
[self dismissViewControllerAnimated:YES completion:nil];
see the post https://stackoverflow.com/a/12651085/2787026
Related
I have a button to share my app's link. I want a dialog box for it. I have searched a lot for it but haven't found a satisfactory solution. How can I share my application link to different social platforms, like Facebook, Twitter or Gmail?
I'm using this code:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *textToShare = #"Look at this awesome website for aspiring iOS Developers!";
NSURL *myWebsite = [NSURL URLWithString:#"My URL"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
// Do any additional setup after loading the view.
}
You can create your Share Action Button directly from Interface Builder and ctrl drag it into your code.
Then you can do something like this :
- (IBAction)shareByFacebook:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[self generateMessage:controller];
}else{
UIAlertView* facebookAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Social.Account.FB.title", #"") message:NSLocalizedString(#"Social.Account.FB.message", #"") delegate:nil cancelButtonTitle:NSLocalizedString(#"Error.ok", #"") otherButtonTitles: nil];
[facebookAlert show];
}
}
This method share an image and a corresponding text message to Facebook.
- (IBAction)shareByTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[self generateMessage:tweetSheet];
}else{
UIAlertView* twitterAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Social.Account.Twitter.title", #"") message:NSLocalizedString(#"Social.Account.Twitter.message", #"") delegate:nil cancelButtonTitle:NSLocalizedString(#"Error.ok", #"") otherButtonTitles: nil];
[twitterAlert show];
}
}
Same for Twitter.
Don't forget to import #import <Social/Social.h>
I have created a generic generateMessage method in order to avoid code repetition.
-(void)generateMessage:(SLComposeViewController *)controller
{
if ([controller.serviceType isEqualToString:SLServiceTypeTwitter]) {
NSString* message = #"The message you want."
[controller setInitialText:message];
}
[controller setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
DDLogInfo(#"Posted");
} else if (result == SLComposeViewControllerResultCancelled) {
DDLogInfo(#"Post Cancelled");
} else {
DDLogInfo(#"Post Failed");
}
}];
[self.parentVC presentViewController:controller animated:YES completion:nil];
}
Those methods enable you to share content (images, photos, message..) to your Facebook/Twitter and Google account directly from your app.
N.B: For Google it's a little bit different because their share method is now deprecated
Share Google+ iOS
But you can use the old way, like this example in order to share an URL for example :
- (void)showGooglePlusShare:(NSURL*)shareURL {
// Construct the Google+ share URL
NSURLComponents* urlComponents = [[NSURLComponents alloc]
initWithString:#"https://plus.google.com/share"];
urlComponents.queryItems = #[[[NSURLQueryItem alloc]
initWithName:#"url"
value:[shareURL absoluteString]]];
NSURL* url = [urlComponents URL];
if ([SFSafariViewController class]) {
// Open the URL in SFSafariViewController (iOS 9+)
SFSafariViewController* controller = [[SFSafariViewController alloc]
initWithURL:url];
controller.delegate = self;
[self.parentVC presentViewController:controller animated:YES completion:nil];
} else {
// Open the URL in the device's browser
[[UIApplication sharedApplication] openURL:url];
}
}
EDIT :
You can create only 1 IBAction button in order to share to social network.
And then the user has to choose which one.
The result will be something like this :
And the code example :
- (IBAction)shareContentSocialNetwork:(id)sender
{
if ([UIAlertController class]){
// ios 8 or higher
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"" message:#"Share on Social Network" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* fb = [UIAlertAction actionWithTitle:#"Facebook" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// Create a method in order to add image, text etc..
[self generateMessage:controller];
}else{
UIAlertView* facebookAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Social.Account.FB.title", #"") message:NSLocalizedString(#"Social.Account.FB.message", #"") delegate:nil cancelButtonTitle:NSLocalizedString(#"Error.ok", #"") otherButtonTitles: nil];
[facebookAlert show];
}
}];
[alertController addAction:fb];
UIAlertAction* twit = [UIAlertAction actionWithTitle:#"Twitter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
// Create a method in order to add image, text etc..
[self generateMessage:controller];
}else{
UIAlertView* twitterAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Social.Account.Twitter.title", #"") message:NSLocalizedString(#"Social.Account.Twitter.message", #"") delegate:nil cancelButtonTitle:NSLocalizedString(#"Error.ok", #"") otherButtonTitles: nil];
[twitterAlert show];
}
}];
[alertController addAction:twit];
UIAlertAction* ggl = [UIAlertAction actionWithTitle:#"Google+" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
NSURL *url = [[NSURL alloc] initWithString:#"yourContentURL"];
[self showGooglePlusShare:url];
}];
[alertController addAction:ggl];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil];
}
}
Basically I am creating the 3 specific actions of the AlertController.
For Twitter and Facebook it is pretty straightforward, even so you have to use the generateMessage method I showed you earlier.
Hope it helps.
I am using SLComposeViewController for sharing in Twitter and Facebook in my app. It is working fine for Twitter but for Facebook, SLComposeViewController closes automatically on selecting location. This is an iOS 8 issue. Working fine on iOS7.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
// [fbSheet dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
if([NetworkManager SharedInstance].isInternetReachable){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Feeds shared successfully."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
break;
}};
[self.fbSheet setCompletionHandler:completionHandler];
NSString *fbString= self.titleString;
[self.fbSheet setInitialText:fbString];
[self.fbSheet addURL:[NSURL URLWithString:self.urlString]];
[self presentViewController:self.fbSheet animated:YES completion:nil];
}
The control is automatically going into completion handler block with result as cancelled. I have gone through some posts suggesting it is 64 bit architecture problem. Please help me with this if anyone is facing the same issue.
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[self.fbSheet setInitialText:#"Social Framework test"];
[self.fbSheet addImage:[UIImage imageNamed:#"imagename.png"]];
[self.fbSheet addURL:[NSURL URLWithString:#"URL_NAME"]];
[self.fbSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Post Sucessful");
NSLog(#"Posted....");
if([NetworkManager SharedInstance].isInternetReachable){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Feeds shared successfully."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
break;
default:
break;
}
}];
[self presentViewController:self.fbSheet animated:YES completion:nil];
}
}
I've developed an app that allows the user to text contacts that they add in the app. The problem I'm having is it seems that if the user already exists in the person's native iOS address book, the text will send no problem. But if the contact exists only within the app, the text will not go through. Has anyone else experienced something like this before?
EDIT: Code below
if([MFMessageComposeViewController canSendText])
{
controller.body = #"";
controller.recipients = arrayContactMobileStrings;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Message not sent", #"") message:NSLocalizedString(#"Error sending message", #"")
delegate:self cancelButtonTitle:NSLocalizedString(#"OK", #"") otherButtonTitles: nil];
switch (result)
{
case MessageComposeResultCancelled:
[alert show];
break;
case MessageComposeResultFailed:
[alert show];
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
Am using SLComposeViewController for posting articles to facebook wall.When App permission is turned off for facebook in device settings,
SLComposeViewController still Works by posting article to facebook wall.Is this a SDK issue?
SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
{
[facebookViewController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Action Cancelled"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
case SLComposeViewControllerResultDone:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Posted to Facebook successfully"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
}};
[facebookViewController addImage:_shareImage];
[facebookViewController setInitialText:_shareTitle];
[facebookViewController addURL:_shareLink];
[facebookViewController setCompletionHandler:completionHandler];
[self.dashboard presentViewController:facebookViewController animated:YES completion:nil];
}
I found out the answer myself.
Check the below code
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0"))
{
ACAccountStore *accountStore=[[ACAccountStore alloc]init];
ACAccountType * facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = #[#"publish_stream"];
NSDictionary * dict = #{ACFacebookAppIdKey : #"facebook_appid", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil)
{
SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
{
[facebookViewController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
[self dismissView];
}
break;
case SLComposeViewControllerResultDone:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Posted to Facebook successfully"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
}};
[facebookViewController addImage:_shareImage];
[facebookViewController setInitialText:_shareTitle];
[facebookViewController addURL:_shareLink];
[facebookViewController setCompletionHandler:completionHandler];
[self.dashboard presentViewController:facebookViewController animated:YES completion:nil];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissView];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message: #"App Permissions disabled in facebook settings."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
});
}
}];
I'm creating an application that has integration with Twitter .. and wanted to know what have to do to create a button to add an image of the device in the tweet.and also wanted to know which framework to use it and also where the code
You can just use the twitter framework, it's included since iOS 5
And the code i use:
- (IBAction)twitter:(id)sender {
if([TWTweetComposeViewController canSendTweet])
{
NSLog(#"Ready to Tweet.");
TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer setInitialText:[NSString stringWithFormat:#"My message"]];
[tweetComposer addImage:[UIImage imageNamed:#"114x114"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://myPage"]];
tweetComposer.completionHandler = ^(TWTweetComposeViewControllerResult result){
if(result == TWTweetComposeViewControllerResultDone){
NSLog(#"Tweeted.");
} else if(result == TWTweetComposeViewControllerResultCancelled) {
NSLog(#"Cancelled.");
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
};
[self presentModalViewController:tweetComposer animated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:#"You can't send a tweet 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];
[alert show];
[alert release];
}
}