Facebook integration work, but not on my iPhone - objective-c

I have a little question about my Facebook integration in my App.
In my Simulator, it's all perfect, but if I am testing the app at my normal
IPhone (5) the Facebook post window don't open. I get no error or warnings but nothing happens.
Maybe you have any ideas, thank you!
Have a nice day!
//edit: my code
- (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];
}
}

Just remove this check:
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]
Here is how your code should look like:
- (IBAction)postToFacebook:(id)sender {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[self presentViewController:controller animated:YES completion:Nil];
}
Apparently if you are not logged into Facebook (Settings -> Facebook) then it will return false on the iPhone but returns true on Simulator.

Related

setInitialText not work with IOS 8.3 (facebook,social,SLComposeViewController)

The functionality of SLComposeViewController no longer works as expected with the newest Facebook iPhone app update as of April 24th. Any initial text specified is ignored, though the setInitialText method returns true as if it was successful. The dialog then always returns "Done" whether you hit "Done" or "Cancel". I realize this is an Apple call and I'm not even using the Facebook SDK, but I have verified that everything works perfectly with the previous version of the Facebook App installed but when you upgrade the Facebook app on your iPhone, this functionality no longer works as expected.
Note that the result of the completion handler now always returns "Done" - even when you hit "Cancel" and also, the setInitialText: does nothing now. Verified that the same code worked pre-the april 24th release.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"hiiiiiii"];
[controller setCompletionHandler:^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"The user cancelled.");
}
else if (result == SLComposeViewControllerResultDone)
{
NSLog(#"The user posted to Facebook");
}
}];
[self presentViewController:controller animated:YES completion:nil];
}
else
{
SCLAlertView *alert = [[SCLAlertView alloc] init];
[alert showWarning:self title:#"alert" subTitle:#"facebook not installed" closeButtonTitle:#"ok" duration:0.0f];
}
At the time of this post, FB's still not allowing to set initial text, even using FB SDK.
A way I implemented to bypass the issue is to copy the content to clipboard and show a dialog to notify users that they can paste the preset content.
setInitialText: is not working anymore because Facebook has recently changed its policy about prefilling, but addURL: is still working and may be useful.
SLComposeViewController *mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSURL *url = [[NSURL alloc] initWithString:linkString];
[mySLComposerSheet addURL:url];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"SLComposeViewControllerResultCancelled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"SLComposeViewControllerResultDone");
break;
}
}];
This way I can prefill Facebook post composer with the URL to my App.
I hope it to be useful.

How do I post my own app with facebook

I have made an app and I want to create a UIButton that shares this app with facebook users.
I wrote the following code:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My App Name"];
[controller addURL:[NSURL URLWithString:#"https://itunes.apple.com/il/app/fruit-ninja-free/id403858572?mt=8/"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else {
}
I've used an example URL of the famous fruit ninja cause my app is not yet on the app store and doesn't have it's own URL.
The issue:
If the app is not yet on iTunes, I don't have an iTunes URL to share yet... So how do I share my app?
Help is much appreciated...
You should create stub for your app at iTunes Connect. After that you'll be able to get link to your application even before submission.

MPMediaPickerController - iOS7

I developed test application on iOS 7 that pick the music from music library using MPMediaPickerController.
But when I present the media picker controller,it shows empty screen.
This is the code
(void) pickSong
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = NSLocalizedString(#"Select Your Favourite Song!", nil);
[mediaPicker loadView];
[self.navigationController presentViewController:mediaPicker animated:YES completion:nil];
}
#pragma mark - MPMediaPickerController delegate
(void) mediaPicker:(MPMediaPickerController *) mediaPicker2 didPickMediaItems:(MPMediaItemCollection *) mediaItemCollection {
[self dismissViewControllerAnimated:YES completion:nil];
MPMediaItem *mediaItem = [[mediaItemCollection items] objectAtIndex:0];
self.item.soundName = [mediaItem valueForProperty:MPMediaItemPropertyTitle];
self.item.soundUrl = [[mediaItem valueForProperty:MPMediaItemPropertyAssetURL] absoluteString];
}
(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
Please help me out.
This is an iOS bug, but it only occurs when running a 32 bit build on a 64 bit (A7) device (Only iPhone 5S for now). To work around it, add a 64 bit architecture to your app. (Open build settings in xcode, and change Architecture from $ARCHS_STANDARD to $ARCHS_STANDARD_INCLUDING_64_BIT.) You will then probably need to fix a number of compile, link and runtime issues. See Apple's 64-Bit Transition Guide.
Seems like there is a bug in ios7 where it doesn't like to be presented inside a uinavigation controller - try presenting it directly from a view controller.
I had the same problem and for me the solution was a combination of two of the solutions presented here. First I had to convert my app to be 64-bit ready by changing Architectures to "standard... (including 64-bit)". Once I corrected all the warnings that caused, I had to change the MPMediaPickerController to be presented modally rather than on the navigation stack:
- (IBAction)didSelectMusicPicker:(id)sender {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"Add songs to play", "Prompt in media item picker");
//[self.navigationController pushViewController:picker animated:YES];
[self presentViewController:picker animated:TRUE completion:NULL];
}
Of course, I also needed to change mediaPicker:didPickMediaItems: and mediaPickerDidCancel: to use dismissViewControllerAnimated. Once all that was fixed, the picker worked as expected on both iPhone 4 and iPhone 5S running iOS 7.
a thought: is the presented screen completely empty, or are you getting the navigation bar at the bottom but with no tracks listed? I've noticed that as of iOS 7 the picker now defaults to opening to the Playlist tab (it used to open to Albums, if I recall)… if you have no playlists on the device that would account for the empty screen…
I can see the list of songs and select the songs. But I cannot dismiss the view controller on pressing "Done". I've tried PresentViewController since Modal controller is deprecated.
- (IBAction) showMediaPicker: (id) sender {
picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"AddSongsPrompt", #"Prompt to user to choose some songs to play");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
[self.picker removeFromParentViewController];
[self presentViewController:picker animated:YES completion:nil];
// [picker release];
}
// Responds to the user tapping Done after choosing music.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
[self.picker removeFromParentViewController];
[self dismissViewControllerAnimated:YES completion:nil];
//
[self.delegate updatePlayerQueueWithMediaCollection: mediaItemCollection];
// [self.mediaItemCollectionTable reloadData];
// [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
I've tried RemovefromSuperview also, nothing seems to work. I'm testing this on an iPhone 6 simulator and an iPhone 5 with iOS 8.1.3.
Anyone???
I also have the same problem before. But I found out just need to restart the device after upgrade. The music picker appear again.

Twitter Framework for ios6 how to login through settings from app

For iOS5 we can refer :
Prompt login alert with Twitter framework in iOS5?
But for iOS6 that will not helpfull i have tried in following way but there is 1 keyboard appearance issue is present is there any one who can help me on this :
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.view.hidden=TRUE;
[self presentViewController:tweetSheet animated:YES completion:^{
[tweetSheet.view endEditing:YES];
}];
I have make one small change and the issue gone away
in above code when presenting viewcontroller just set animated:NO
[self presentViewController:tweetSheet animated:NO completion:^{
[tweetSheet.view endEditing:YES];
}]

iOS6 Twitter integration

There seems to be a difference between the iPhone simulator and actual device when checking if Twitter is available.
I check if a Twitter account is setup by using this code: [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter];
In the simulator there is a nice UIAlertView informing the user that there are no Twitter accounts setup and two buttons one for Settings and one for Cancel.
However when I run my app on my device it will not show the above UIAlertView. Why is that? And how can I catch what button is tapped in the above UIAlertView (since I did not instantiate it?)
This is what it looks like on the simulator:
To handle the result of the Twitter call, You can use this snippet :
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[twitterController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
}
break;
}};
[twitterController setCompletionHandler:completionHandler];
...
...
}
I also am having the same issue that the device doesn't display the UIAlert like the simulator does. Until Apple fixes it, this is what I'm doing (not as clean or nice as the simulator, and requires the user to manually go to the homescreen) Apple, please fix this!
Edit: the stock Apple apps show the UIAlert perfectly of course, example: sharing a photo from the photo app without having a Twitter/Facebook account will display the correct UIAlert.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:#"Check out the app:"];
[mySLComposerSheet addImage:[UIImage imageNamed:#"test.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://urlofyourapp.com"]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"You need to setup an account in the Settings app under Twitter to use this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled){[mySLComposerSheet dismissModalViewControllerAnimated:YES];}
else if (result == SLComposeViewControllerResultDone){[mySLComposerSheet dismissModalViewControllerAnimated:YES];}
}];