Open my app from a FB app status (iOS) - ios

I am trying to open my app via the Facebook app's status but my link shows up as text instead of a link. It does works with both SMS and Email but does not FB or Twitter status'.
I have a URL Scheme set up in my Info.plist.
My link is (appName is my URL Scheme name given)
Also I am calling FB, Twitter, & everything else with
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
NSBubbleData *sayBubble = [NSBubbleData dataWithText:textField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
[bubbleData addObject:sayBubble];
[bubbleTable reloadData];
textField.text = #"";
NSLog(#"%#, %d", activityType, completed);
}];
[self presentViewController:activityController animated:YES completion:nil];
Trying to keep everything native to iOS.

Have a look at https://developers.facebook.com/docs/applinks for your Use Case.

Related

Facebook sharing on iOS works on some devices, but not others

So I am doing just a basic facebook share inside my app, and it works fine on my devices (iPhone 6 OS 9.1 and iPad air 9.02) but doesn't work on my coworkers iPad Air 2 8.4.1 or iPhone 6 Plus 9.1. Anyone have any clue as to why this would be?
They are signed into facebook in the device settings. They also have the facebook app installed (I don't have the app, just signed in through settings)
Here's the screenshot of my device showing the message to share, the other devices just show the image and no text.
Here's the code I am using to share
- (void)shareTapped {
UIImage *image = self.pictureView.image;
NSString *postText = [NSString stringWithFormat:#"%#\n*%#\n%#\n%#, %# %#", self.event.shortDescription, self.event.eventCode, self.event.address, self.event.city, self.event.state, self.event.zip];
[[UtilitiesObject sharedInstance] shareMessage:postText image:image parentVC:self];
}
- (void)shareMessage:(NSString *)msg image:(UIImage *)image parentVC:(UIViewController *)parentVC {
NSArray *activityItems = #[msg];
if (image) {
activityItems = #[msg, image];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
// Tailor the list of services displayed
activityController.excludedActivityTypes = #[UIActivityTypeAssignToContact,
//UIActivityTypePostToFacebook,
//UIActivityTypePostToTwitter,
//UIActivityTypeMail,
UIActivityTypeMessage,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePrint,
UIActivityTypePostToWeibo,
UIActivityTypeCopyToPasteboard];
activityController.popoverPresentationController.sourceView = parentVC.view;
[activityController setCompletionWithItemsHandler:
^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
if ([activityType isEqualToString: UIActivityTypeMail]) {
NSLog(#"Mail");
}
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
NSLog(#"Facebook");
}
if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
NSLog(#"Twitter");
}
}];
[parentVC presentViewController:activityController animated:YES completion:nil];
}
Facebook's platform policy does not allow apps to prefill the message field. In this case, because you don't have the Facebook app, it's using Apple's share sheet, which allows prefill but is against FB's platform policy. In your friends case, they're likely seeing the Facebook app's share extension, which correctly enforces the policy, and does not allow prefill.

SLComposeViewController post both image and url ios9

What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device.
And this one is when the Facebook app is not installed on the device
And this is my code:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:#"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"icon_circle"]];
[controller setInitialText:#"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
So If you want to share everything, better use FB SDK.
So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.
Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:
If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.
If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.
For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup
I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}

Unlock a feature when the user shares the app via Facebook/Tweeter in iOS, Swift?

Is there such feature that can be un-locked when the user shares my app via Facebook or Tweeter?
Like this:
1) The user clicks on "Share" button within my app
2) My app is then posted(shared or advertised) on the wall of the user's facebook
3) Some feature gets unlocked within my app
You can use the Facebook sharing delegate method to know whether the user has successfully shared OR not.
Below is FB developer link which show various sharing methods,according to your requirements.
https://developers.facebook.com/docs/sharing/ios
Below are the methods in which you can know the sharing status
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{
//UNLOCK THE APP FEATURE IN THIS METHOD
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
NSLog(#"%#",error);
}
See iOS Facebook Tutorial for an example of how its done on the facebook end.
On the app side you can setup a flag on NSUserDefaults or write to the app filesystem to check if the feature is unlocked.
This can be done relatively painlessly using UIActivityViewController and its completion handler.
NSString *message = #"my app is awesome.";
NSURL *link = [NSURL URLWithString:#"awesomeapp.com"];
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:#[message, link]
applicationActivities:nil];
//add whatever you don't want
shareController.excludedActivityTypes = #[UIActivityTypeMessage];
shareController.completionWithItemsHandler =
^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
//Share wasn't completed, don't unlock
if (!completed || activityError) {
return;
}
//Facebook or Twitter
if ([activityType isEqualToString:UIActivityTypePostToFacebook] ||
[activityType isEqualToString:UIActivityTypePostToTwitter]) {
//Unlock item logic
}
};
[self presentViewController:shareController animated:YES completion:^{
//Whatever
}];

How to detect when Facebook share has been cancelled from UIActivityViewController setCompletionWithItemsHandler

The completion handler seems to work correctly for all the other share types (Twitter, Mail) but for Facebook, the complete BOOL is YES even when you cancel the share (having first tapped the Facebook icon).
UIActivityViewController *shareActivity = [[UIActivityViewController alloc] initWithActivityItems:#[title, url] applicationActivities:nil];
[shareActivity setCompletionWithItemsHandler:^(NSString *activityType, BOOL complete, NSArray *returnedItems, NSError *activityError) {
if (complete) { //Facebook share is always YES }];
Any suggestions?
iOS 8.3, Facebook App installed.

UIActivityViewController In iOS 7 Missing Options

I was using the following code with iOS 6 SDK to implement UIActivityViewController:
-(IBAction)Share:(id)sender
{
NSArray *activityItems = #[self.title, urlString];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Successfully Shared" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
} else
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Unable To Share" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
}
}];
}
The above code in iOS 7 is giving me the following output:
Earlier there wasn't Facebook and Twitter in the share sheet but i signed into both both these apps in the Settings and Facebook and Twitter started appearing.
PROBLEM: Belo the line, there is only COPY and other like BOOKMARK, ADD TO READING LIST, ADD TO HOMESCREEN, PRINT and AirDrop buttons are not showing up. What can i do to bring these? Thanks!
UPDATE: I have added the print button by using one answer below, how can i add the rest?
Bookmark, Add To Reading List, and Add To Homescreen are only available in safari, unless you define them yourself. To add those buttons, you need to create an applicationActivities NSArray, populated with UIActivity objects for various services. You can pass this array into the initWithActivityItems:applicationActivities: UIActivityViewController method (you were passing nil for this parameter).
You should use UISimpleTextPrintFormatter to show PRINT:
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
initWithText:self.title];
NSArray *activityItems = #[self.title, printData];
Follow #Arkadiusz Holko and #Santa Claus answers to add another functionality.
You should use NSURL object instead of NSString when you want an element to be treated as a URL. Replace:
NSArray *activityItems = #[self.title, urlString];
with
NSArray *activityItems = #[self.title, [NSURL URLWithString:urlString]];
Then follow #Santa Claus's advice if you want elements other than Add to Reading List to be visible.

Resources