Facebook share functionality is not working in iOS8 - objective-c

I have implemented Facebook sharing functionality using social framework. I have configured the Facebook account using device setting. When I installed the Facebook app on device, sharing is not working as expected.
When share window appears, it only has the image for sharing and no initial text and URL.
iOS8 - Share functionality is working properly if I remove the Facebook app from device.
iOS7 - Share functionality is working properly even the Facebook app is on device.
I am not sure where it is a framework issue or something is missing?
SLComposeViewController *facebookShareVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSString *imagePath = [NSString stringWithFormat:#"%#/%#_%#_%#.gif", [[STInteractionManager sharedManager] getAppLibraryCacheDirectory], article.journalID, article.volume, article.issueNumber];
UIImage* img = [[STInteractionManager sharedManager] imageNamedFromDocuments:imagePath];
[facebookShareVC setInitialText:self.articleTitle];
[facebookShareVC addURL:[NSURL URLWithString:[self.url stringByReplacingOccurrencesOfString:#"?dispform=ios-device" withString:#""]]];
[facebookShareVC addImage:img];
[self presentViewController:facebookShareVC animated:YES completion:nil];

If you want to pre-fill the fields, you shouldn't use the Facebook SDK at all. Instead, use the Social framework provided by Apple. With only a few lines of code, you can trigger the SLComposeViewController.

Related

Unable to access iPhone Gallery in iOS 10

I am trying to access photos gallery in ios 10. But my application got crash every time. I have added required privacy permission in info.plist
Please check my code below and let me know, where i have gone wrong.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
I have added Privacy - Media Library Usage Description in info.plist
I am getting below message in my console
http://prntscr.com/eg756r
In 'info.plist' you should use
Privacy - Photo Library Usage Description
Which will allow your app to access photo library
in intfo.plist File you need to add NSPhotoLibraryUsageDescription
To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s photo library
Please Check Below Post for more Info
https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html
This should help. Here’s a mapping of each of the values that you can find and add the relevant permission key to the Info.plist:
Bluetooth Sharing – NSBluetoothPeripheralUsageDescription
Calendar – NSCalendarsUsageDescription
CallKit – NSVoIPUsageDescription
Camera – NSCameraUsageDescription
Contacts – NSContactsUsageDescription
FaceID - NSFaceIDUsageDescription
Health – NSHealthShareUsageDescription & NSHealthUpdateUsageDescription
HomeKit – NSHomeKitUsageDescription
Location – NSLocationUsageDescription, NSLocationAlwaysUsageDescription, NSLocationWhenInUseUsageDescription
Media Library – NSAppleMusicUsageDescription
Microphone – NSMicrophoneUsageDescription
Motion – NSMotionUsageDescription
Photos – NSPhotoLibraryUsageDescription
Reminders – NSRemindersUsageDescription
NFC - NFCReaderUsageDescription
Speech Recognition – NSSpeechRecognitionUsageDescription
SiriKit – NSSiriUsageDescription
TV Provider – NSVideoSubscriberAccountUsageDescription

playing a youtube movie from url in objective C

I have a tableview which contains youtube urls.
http://www.youtube.com/v/M67PNWvKdg0&autoplay=1
I am trying to play the video file with the following piece of code. I also imported the media framework.
Video *video = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSURL *urlString=[NSURL URLWithString:video.url];
//NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
//pathForResource:#"Video1" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:urlString];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
What it does for now is it pops up a movie player but then immediately goes back to my tableview. Does anybody knows what the problem is?
Thanks in advance
Are you working on iOS 6? I found difficulty in playing Youtube videos through MPMoviePlayerController, so I found out this to be very useful.
This has MPMoviePlayerController only...
And this would work well for Versions < iOS 6 too.
You can't play youtube videos via Media Player. You have only two solutions: open the link via external app (just open it and iOS will run Safari or YouTube.app if installed) or you can implement your own view with UIWebView and open the link inside WebView.
May be this link would help you, and one more thing is the video plays only on device cant test on a simulator.
There's another way but you have to be a little adventurous.
You can use a third party rtsp framework of which there are a few.
Then you need to link to the m.youtube.com, this is the rtsp version of youtube that Android and other phones will get you to.
If you try to open this link in safari on the iphone the page redirects to the h264 links.
You can open the url in an uitableview and change the user-agent tag. Or simply copy the links you want into a table.
Are all youtube videos automatically converted to h264 now, at one time I remember they were a subset of the rtsp pages.
If you have an Android device you can access this page in a webview quite easily.
here check this link out.
http://streammore-tv.tumblr.com/post/34794206547/welcome

Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?

I have just integrated facebook into my app via ios 6 but I have an issue when posting on my wall. It simply says "post via ios app". I want it to say "posted via the app name". I have made an app identity with facebook and I have the app number they have assigned but I am not sure how to integrate this with facebook integration.
Below is my code. If anyone could help, it would be appreciated. Thanks!
{
NSString *message;
message= [[NSString alloc] initWithFormat:#"I've earned %# points", [self retrieveScore]];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:message];
[controller addURL:[NSURL URLWithString:#"http://mysite"]];
[self presentViewController:controller animated:YES completion:Nil];
[message release];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
NSString *output= nil;
switch (result) {
case SLComposeViewControllerResultCancelled:
output= #"Action Cancelled";
NSLog (#"cancelled");
break;
case SLComposeViewControllerResultDone:
output= #"Post Succesfull";
NSLog (#"success");
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
}
UPDATE - it can be done
So the Digg for iOS app is able to share to Facebook without using the Accounts framework to get user permissions... They use UIActivityViewController and have the post appear as "via Digg", I contacted someone from Digg and they told me that it's a manual process, you must have your iOS app published in the Apple App Store and also have your Facebook application accepted and published in the Facebook App Store.
Then Facebook can manually process linking the two in this way.
The obvious downside to this is that UIActivityViewController meant that you can share from your app without any integration with Facebook, no need for a Facebook app... But to get "via Your App Name" you will need a Facebook app that Facebook will approve into their own app store, once everything is live, you'll need to contact developer relations to link it all up.
Note that the rest of my answer (my previous answer) is correct, the solution is a manual process that Facebook can do for you, your iOS code shouldn't be affected.
Previous Answer and workaround
The native Facebook integration you want is actually the composer view controller. This is obtained by using the SLComposeViewController class with service type SLServiceTypeFacebook.
This class only provides a one way communication and as you notice, you are the one confirming any wall posts by tapping the Post button. This view controller is owned by the iOS system, not your app. And by interacting with this compose view controller you are actually bypassing your application.
Users like to do this because it gives them security.
Unless your application functions only by a deeper, two-way Facebook integration you should use the SLComposeViewController (deeper integration meaning your app needs your friends list or existing wall posts, albums etc...).
In order for a post originating from your application to appear on Facebook with the "via xxxx" and not "via iOS", you need to interact with Facebook via the SLRequest class. In order to do this you must also interact with the Account.framework in addition to Social.framework.
It resembles the previous Facebook iOS SDK previously used (and still can use) in terms of setting it up, you get a reference to the Accounts store of the device, you request for Facebook accounts and send your Facebook app ID and an array of permissions.
If granted you may then interact with the Facebook Graph API via the SLRequest class. By posting to your wall in this manor you will have the desired "via xxx".
To use this please check out the documentation for SLRequest.
Please note that you are responsible for creating your own compose view in this case.
You can of course inspire yourself from the native UI, also check out iPhoto's iOS app, try sharing to Facebook with that app, you will notice it requests permission to interact with your Facebook account (something that does not occur when using SLComposeViewController), it then presents something very close to the SLComposeViewController for Facebook post composing.
But if you look closer you'll notice it is not the same. This also goes for Twitter and their native app vs native integration. They have their own compose view, it's really interesting to note they use the native iOS integration (the Apple frameworks). We know this because going to Settings > Privacy > Twitter you can see Twitter app is an authorised app using the Twitter account(s) on the device.
Same goes for Facebook.
If you don't get permission then you have no way of publishing as your app - aka "via myApp".
Sorry to let you down, I also had been searching a way to integrate an ACAccount into the SLComposeViewController but couldn't find the way either. Which is a shame... because the native UI is sweet.
I ended up using a custom Facebook framework with the new Facebook SDK 3.1.
Facebook Compose View
The original is here: facebook compose view. I've just fixed a few minor warnings and updated with the new FB SDK 3.1.
Usage:
DEFacebookComposeViewControllerCompletionHandler __block completionHandler = ^(DEFacebookComposeViewControllerResult result) {
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case DEFacebookComposeViewControllerResultCancelled:
NSLog(#"Facebook Result: Cancelled");
break;
case DEFacebookComposeViewControllerResultDone:
NSLog(#"Facebook Result: Sent");
break;
}
};
DEFacebookComposeViewController * compose = [[DEFacebookComposeViewController alloc] init];
[compose setInitialText:self.shareText];
[compose addImage:self.shareImage];
[compose addURL:self.shareURL];
[compose setCompletionHandler:completionHandler];
[self presentViewController:compose animated:YES completion:^{}];
Setup:
Open the project and do a clean build.
Go into the folder $PROJECT_FOLDER\build\Debug-iphonesimulator and drag both the FBComposeView.framework & FBComposeView.bundle into your project.
Note: Be sure to use the ones in the Debug-iphonesimulator. It is the fat binary.
We solved similar problem with iOS 5 Twitter integration, and the result is:
When posting to Twitter with a dev build or via the simulator it will almost always show up on Twitter as "via iOS". Once your app is approved and you post from the AppStore build it should show up as posted by "YourAppName on iOS" with a link to the apps appstore page.
original source (ShareKit issue discussion)
I suppose Apple does the same with Facebook and other social services.
EDIT: unfortunately this only really worked with Twitter.framework. I think the best explanation and answer is the Daniel's one above. Maybe it is a time to radar it, so that Apple knows, what do we want.
Examples of how to use SLRequest with Facebook are in this SO question
EDIT2: filed a radar Bug ID# 12980058. Hopefully they listen...

iOS keep gps permission during the session

My app loads a jquery + google maps file into webview and when viewDidLoad activates an alert asking for gps accessing (as normal). After validating it, if this view is reloaded later, still pushing the alert! how to keep gps permissions in order to avoid multiple alerts asking for permission? Thank you.
I would try to access the GPS from native Obj-C code first, and after that let the webview to load:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[locationManager stopUpdatingLocation];
This should validate your app to use the GPS, and therefore the Webview to use it (at least if it is a local webview, not sure if it is remote).

Go to iPhone maps app from another app

I'm writing an app where I want the user to be able to get directions. I know about the google API, and I have that implemented, but I was wondering about ways to jump directly to the native Maps app and give the user directions instead. I think I've seen it done before, but I could be mistaken.
Any help is much appreciated.
You can open the maps app by using regular URL that points to Google Maps. From the Apple URL Scheme reference:
The maps URL scheme is used to show geographical locations and to generate driving directions between two points. If your application includes address or location information, you can use map links to forward that information to the Maps application on iOS and the Google Maps website on other platforms.
Unlike some schemes, map URLs do not start with a “maps” scheme identifier. Instead, map links are specified as regular http links but are targeted at the Google Maps servers. The following examples show the strings you would use in Safari and in a native application to show a map of the city of Cupertino, California.
HTML link:
Cupertino
Note that on a device that does not have maps installed (not sure if those even exist), the link will open in a regular browser, since it is simply an HTTP link.
To open the URL, you can present the link in a UIWebView, or you can use code to open it. for example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=Cupertino"]];
If you wanted to pass in a custom location and open it when the user taps a button, you can make a method like this:
- (IBAction) openMapsAppAndShowLocation:(NSString *)locationToShow{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=%#", locationToShow]]];
}
If you wanted, you could refactor the method to take latitude/longitude pair too. That might look like this:
- (IBAction) openMapsAppAndShowLatitude:(double)latitude andLongitude:(double)longitude{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=\"%f,%f\"", latitide, longitude]]];
}
You can use either this:
NSString *latlong = #"-56.568545,1.256281";
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#",
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
this,
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: #"http://maps.google.com/maps?q=London"]];
or this
[someUIApplication openURL:[[NSURL alloc] initWithString: #"http://maps.google.com/maps?q=London"]]
You can even specify the zoom level using the z flag (values between 1-19):
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?z=8"]];
That should invoke the Google Maps app. I think that these instructions only work on the actual device and NOT in the simulator. Good luck and comment below if you have any problem with the snippets :)
Very simple
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]];
Easy as a kiss
#Moshe
Note that on a device that does not have maps installed (not sure if those even exist)
Take an iPhone simulator for example.