Social.framework don't work on device - iphone

I want make button for share on Facebook with the social.framework. I make this:
#import <UIKit/UIKit.h>
#import <Social/Social.h>
#interface SocialSharingViewController : UIViewController
- (IBAction)postToFacebook:(id)sender;
#end
Then I add in m. File:
- (IBAction)postToFacebook:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[self presentViewController:controller animated:YES completion:Nil];
}
}
It's work perfect in emulator but when I test this on my iPhone 5 device it's doesn't work. When I click on the button postToFacebook nothing happens.
Pleas help me

The possible error is that your iphone 5 is not configured any fb account. [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] will return NO in this case
As per the documentation for the SLComposeViewController, isAvailableForServiceType "returns a Boolean value indicating whether the service is accessible and at least one account is set up... For the account to be available, the user must be logged into the social service in the device settings."
NOTE: Whenever you add a if condition, use else condition too. #codingstandard

Related

iOS SLComposeViewController - url not displaying for twitter post

I am using the SLComposeViewController to post to twitter and Facebook. I have the same code for both twitter & facebook but the URL is not showing up in the twitter post. How do I fix this?
Twitter code -
socialController = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[socialController setInitialText:#"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:#"image.jpg"]];
[socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];
Facebook code -
socialController = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialController setInitialText:#"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:#"image.jpg"]];
[socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];
SLComposeViewController shows the URL as an attachment on tweet compose view. When it is sent, URL will be appended to the end of the post. You may even add multiple URLs, they will be still shown as attachments. So this is the way it should be, there is nothing to fix.
I suggest you actually send the tweet, and check on your Twitter account wether it is really missing the URL or not (it may just be working as expected)
This is apparently not what's causing your troubles, but beware of your message length: I have found out that when the text message is too long, the Twitter API silently skips the steps where it should include the shortened URLs for the image and the URL.
According to this answer, your text should not exceed 113 characters if you use addURL twice.
i suggest to refer this link.. debug your code and there is one method
- (BOOL)addURL:(NSURL *)url that Returns a Boolean value indicating whether the URL was successfully added.
The SLComposeViewController -addURL: method returns a BOOL to indicate if the URL you are trying to attach fits in the character space remaining. Modify your code to check if that is actually returning NO:
BOOL urlOK = [socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
if(!urlOK) {
//Notify the user, truncate the message, or something else depending on your use case
}
Twitter now limits tweets to 117 characters if you include a link

how to come back to app when going to app store from app in ios

going to app store from app using this code
NSURL *myApplicationURL = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication]openURL:myApplicationURL];
Now how can i comeback from app store to app using cancel button.
Thanks for help.
Once you exit your Application you have no way to come back automatically, the user has to open the App again.
You can use show a modal SKStoreProductViewController (available on iOS 6) to show the AppStore inside your Application.
It is easy with the SKStoreProductViewController as redent84 answered and it is introduced in iOS 6+. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project and add #import to header file.
Then find the Apple id of the app by going in iTunes connect manage applications and clicking on app will show you apple id and other details and pass that to the SKStoreProductViewController.
Below is the code
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)AppStoreAction:(id)sender{
NSDictionary *appParameters = [NSDictionary dictionaryWithObject:#"533886215"
forKey:SKStoreProductParameterITunesItemIdentifier];
SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
[productViewController setDelegate:self];
[productViewController loadProductWithParameters:appParameters
completionBlock:^(BOOL result, NSError *error)
{
}];
[self presentViewController:productViewController
animated:YES
completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
In earlier versions you could link to the App Store: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/de/artist/apple/id284417353?mt=12"]] but with this once you exit app you cannot go back to your app.
But with this SKProductViewController you can hit cancel button and go back to your app.
Hope it helps.
try this ........You can use a URL scheme if you have control of the web page. Simply add a link using your scheme.
If your scheme is myapp: then:
Return to the app
See this site for a tutorial. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ refer:Return back to iPhone app from safari

ios 6 - Post to Facebook in app not working on device

I have a button that brings up the Facebook ui to make a post, but it doesn't do anything on the device. It works fine in the simulator, but performs no action at all on the phone.
Not sure what I can do to figure out the problem -
Here is my ViewController.h
- (IBAction)postToFacebook:(id)sender;
ViewController.m
- (IBAction)postToFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"Posted from IOS App Test -- It works!"];
[self presentViewController:controller animated:YES completion:Nil];
}}
You code is working on simulator because isAvailableForServiceType always returns 1 in Simulator. In device you need to setup a facebook account from settings.
Or better just remove this check
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]
With this along with the post sheet an OS alert will appear to notify that account setup is required to post.

iOS 6 Social framework not going to settings or no alert

I'm trying to implement the new social framework in iOS6, and have it working, except for 2 weird problems. If I've enabled the services I'm interested in (say... FaceBook), then it works fine. However, if the accounts are deleted from the settings panel (let's say FaceBook, to be consistent), then I get differing, and frustrating behaviors in the simulator and the device.
Here's the relevant code in my view controller:
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
//check to see if facebook account exists
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
}
And here's the weird behavior when firing off the above method:
In the simulator (version 6.0 (358.4) I get the dialog informing me that I haven't set up any faceBook accounts with "Settings" and "Cancel" buttons. Hitting "Settings" just dismisses the dialog, but doesn't take me to the settings panel.
On my iPhone 4s running 6.01, hitting the button that triggers the method results in... nothing. In other words, I get no dialog informing me that I have to set up a FaceBook account.
Thanks in advance for your help.
OK... Here's the fix:
Here's my new implementation, based on user1734802's helpful comment.
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
At some point I expect
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
to actually work correctly (triggering the automatic dialog, and taking you to settings), so I actually just commented it out in my code.
I had the same problem, i fixed it by removing the If statement:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
Then the view will display although there is no Facebook/Twitter account configured in the settings.
And the "No Facebook/Twitter accounts" alertView showed! And I was able to hit the "Settings" button on the alert, and it directed me to the settings (Configure Facebook/Twitter account in the settings)
This is the code I used, and it works perfectly for me:
- (IBAction)bTwitter:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:#""];
[mySLComposerSheet addImage:[UIImage imageNamed:#""]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

Open a list of my apps in the App Store within my App

I have checked the (Top Paid Apps) sample code from Apple website where you can see all the top apps in the App store, I want to do the same in my app but to show only my apps in the App Store. Here is the URL which i found in that sample :
http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
What do I need to change in this URL to show only my Apps?
This is pretty easy with the SKStoreProductViewController introduced in iOS 6. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project. Then find the iTunes URL that links to your apps using iTunes. You can copy the link from the iTunes Store. For example the URL for the Apple apps is http://itunes.apple.com/de/artist/apple/id284417353?mt=12
It contains the iTunes identifier, that you pass to the SKStoreProductViewController.
Sample code:
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)showMyApps
{
SKStoreProductViewController* spvc = [[SKStoreProductViewController alloc] init];
[spvc loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier : #284417353}
completionBlock:nil];
spvc.delegate = self;
[self presentViewController:spvc animated:YES completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
You could use DAAppsViewController. It can be configured with a developer ID to show all the apps by that developer. It will use StoreKit if available, otherwise fallback to switching to the App Store.