UIActivityViewController share only text - facebook

I want to share just simple text using UIActivityViewController
I am using swift, with xcode 6.3
The code is very simple, work great for photos, but not just text,
I don't want to include any web URL with the objectsToShare, just clean text
Here is the code:
var objectsToShare: ["some text to share"]!
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//handler for completed task
activityVC.completionHandler = {(activityType, completed:Bool) in
if !completed {
println("cancelled")
return
}
reportCompleted() //report to server it's done.
}
//Excluded Activities Code
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList, UIActivityTypeCopyToPasteboard ]
//activate the share view
self.presentViewController(activityVC, animated: true, completion: {
(complete) in
println(complete)
})
Now I know that it's all depends on the user have Facebook - not only on his phone, but also on his setting.
(I tried that directly from my phone 6, which has Facebook setting, and not from the simulator)
This code once worked fine, and still working good for images, and not text, but from some reason, it stop working for text sharing, Maybe the text itself has something to do with, maybe my code is not good, or maybe Facebook, change something.
Thank you for any thought about the subject.
To make thing more strange I found 2 more strange things.
The code of publish text is working on a simulator (as long as you add in the setting facebook)
If I add to the web url it also work (in device) if I remove the web url it is not working.
//code that work:
var myWebsite = NSURL(string: "http://www.someurl.com/")
let textToShare = "Swift is awesome! Check out this website about it!"
objectsToShare = [textToShare , myWebsite!]
//continue regular.
//code that doesn't work:
let textToShare = "Swift is awesome! Check out this website about it!"
objectsToShare = [textToShare ]

It seems that it is not a bug but facebook policy update:
"After discussing this with our team regarding stripping the pre-filling message area of text, this is actually BY DESIGN with the new share extension.
Pre-filling texts violates Platform Policy 2.3 ..... So in all enforcing policy 2.3 is a feature and not a bug. "
https://developers.facebook.com/bugs/949486035103197/

I read and the problem isn't iOS 8.3, is FacebookApp v29 and they haven't fix it on today update. If you uninstall your FacebookApp it works.
I can´t post images, but if you try this code with Facebook app installed and without it you will see the difference
func didPressShare(sender: AnyObject) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
var facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookSheet.setInitialText("This is without facebook on device")
self.presentViewController(facebookSheet, animated: true, completion: nil)
} else {
var alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
As they said: "Sorry for the delay everyone but we have this fix scheduled for v31. The reason for the delay is the cycle for getting updates approved for the App Store takes time. We appreciate your patience."
https://developers.facebook.com/bugs/949486035103197/
They say it will be fixed on next update.

I just tested on my example, using this code:
#IBAction func shareMoment_Action(sender: AnyObject) {
let firstActivityItem = "This is a simple text"
var activityVC = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
activityVC.excludedActivityTypes = [
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop
]
activityVC.completionWithItemsHandler = {(activityType: String!, completed: Bool, arrayOptions: [AnyObject]!, error: NSError!) in
println(activityType)
}
self.presentViewController(activityVC, animated: true, completion: nil)
}
And share is working fine for every option selected!
It is working well on my side. Please check your code again!

I have been facing the same problem but have not been able to fix it. This is what I found out so far:
Bug can be fixed when removing Facebook.app from device (but it's not a solution)
Bug seems to persist on devices with Facebook.app >v28.0 & iOS8.3
Facebook.app v28.0 & iOS8.3 still works
Facebook.app v29.0 & iOS8.2 still works
Sharing URL's seems to be affected too by this bug
It's hard to tell if Facebook actually has something to do with this bug, as they have a policy of entering bogus release notes for updates.
Since the sharing feature is not a main feature in my app, I will wait until the release of iOS8.4 and/or Facebook.app v30.0

After doing some research, I was able to find the following solution to the problem:
func shareTapped() {
let vc = UIActivityViewController(activityItems: [detailImageView.image!, "Check out these photos! http://www.photolib.noaa.gov/nssl"], applicationActivities: [])
presentViewController(vc, animated: true, completion: nil)
So in ActivityItems, you can pass an image then comma and then pass a string variable or open " and enter your text directly " in the enable above this worked with Facebook and Twitter in the UIActivityViewController.

Related

How to filter the images shown on the PHPickerViewController to those selected for limited access

How do I filter the images shown on the PHPickerViewController to those that have been selected under limited access by the user? Or do I need to use a different picker? I've been struggling with this for a few days now. Any help would be appreciated. Thanks in advance.
When user taps the button:
1-5 are automatic
The alert appears with Camera or Photo Library
They choose Photo Library
The authorization alert appears with Select Photo…, Allow Access to All Photos or Don’t Allow
They tap Select Photos = .limited
The presentLimitedLibraryPicker is displayed, for the user to choose the photos thay want to allow and taps Done.
Now I want the picker to appear with a filtered choice of the images the user has just chosen. Seems like this would be automatic too. Not...
This only displays the same picker where the user made the selections for limited access.
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
What goes in the .limited case?
var config = PHPickerConfiguration()
config.selectionLimit = 1
config.filter = PHPickerFilter.any(of: [.images, .livePhotos])
let picker_Photo = PHPickerViewController(configuration: config)
picker_Photo.delegate = self
let libCell = UIAction(title: "Photo Library", image: UIImage(systemName: "photo"), identifier: .none, discoverabilityTitle: .none) { (libAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary)
{
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
switch status
{
case .limited:
DispatchQueue.main.async
{
// PHPhotoLibrary.shared().register(self)
// PHPhotoLibrary.shared().presentLimitedLibraryPicker
self.present(picker_Photo, animated: true, completion: nil)
}
case .authorized:
DispatchQueue.main.async
{
self.present(picker_Photo, animated: true, completion: nil)
}
case .notDetermined:
DispatchQueue.main.async
{
self.present(picker_Photo, animated: true, completion: nil)
}
case .restricted:
self.view.sendConfirmationAlert(theTitle: "Photo Library Restricted",
theMessage: "Photo Library access was previously denied. Please update your Settings to allow access.", buttonTitle: "Ok")
case .denied:
let settingsAlert = UIAlertController(title: "Photo Library Access Denied",
message: "Photo Library access was previously denied. Please update your Settings to allow access.", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Go to Settings", style: .default) { ( action ) in
let settingsUrl = URL(string: UIApplication.openSettingsURLString)
UIApplication.shared.open(settingsUrl!, options: [:])
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
DispatchQueue.main.async
{
settingsAlert.addAction(settingsAction)
settingsAlert.addAction(cancelAction)
self.present(settingsAlert, animated: true)
}
default:
return
}
}
}
}
You are mistaken about what limited access means. It restricts what information you can read and write into the photo library.
But your code does not read from the photo library in the first place. You are saying
config = PHPickerConfiguration()
So this means you have no photo library access at all by way of the picker. You can only get image copies. You therefore do not need any kind of permission to show the picker, and the user limitation makes no difference to you. You can in fact just throw away all your authorization related code; it has no effect. Your picker will work exactly the same without it.
If you needed photo library access by way of the picker, you would have called
https://developer.apple.com/documentation/photokit/phpickerconfiguration/3616114-init
In that case the user limitation would matter to you — when you tried to access an actual PHAsset. But your code never does that. You are asking for a permission you do not need.

UIActivityViewController iOS12.2: strange activity type titles

I'm implementing sharing functionality in my app. I'm sharing some text.
I found that some activity types (such as Mail, Message) in sharing action sheet has strange names (see image below).
On iOS11 everything is OK.
Does anyone know how to fix that?
Code sample:
let activityViewController: UIActivityViewController = UIActivityViewController(
activityItems: ["Hey, look at this URL: https://stackoverflow.com"],
applicationActivities: nil)
activityViewController.completionWithItemsHandler = { [weak self] _, _, _, _ in
//some actions on completion
}
present(activityViewController, animated: true, completion: nil)
The names of apps/actions in the share sheet are not under your control unless you were the one who created the action. I would expect these strange names to disappear in a release build / when it's on testflight so could be worth giving that a shot.

MFMailComposeViewController error [MC] Filtering mail sheet accounts for bundle ID

I do the standard functionality of sending messages with MFMailComposeViewController.
My code:
if MFMailComposeViewController.canSendMail()
{
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["someemail#gmail.com"])
mail.setSubject("Subject")
mail.setMessageBody("Some Text", isHTML: false)
self.presentViewController(mail, animated: true, completion: nil)
}
Controller do not open and I see a message in the console that have never seen.
[MC] Filtering mail sheet accounts for bundle ID: [My Bundle ID], source account management: 1
[MC] Result: NO
Help please.
If a mail account has been set at the device where you try to test your application there is no problem. Please create a mail account.
For Swift 3.0.1 - 4.2 Compatible
if MFMailComposeViewController.canSendMail()
{
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["someemail#gmail.com"])
mail.setSubject("Subject")
mail.setMessageBody("Some Text", isHTML: false)
self.present(mail, animated: true, completion: nil)
}
I had the same error though it works perfectly on my device with iOS 10.1.1.
I had a similar problem and found that the Mail Composer would only work on iOS 9 in the simulator, there is some sort of bug with iOS 10 and running Mail Composer on the simulator with my current knowledge.
Update
I have also tested this with a device with iOS 11.4 and got the same results.
Tried these calls to open mail on the simulator and they did not work. Though work they work fine on a real device.
UIApplication.shared.keyWindow?.rootViewController?.present(mail, animated: true)
self.navigationController?.present(mail, animated: true, completion: nil)
Had the same problem.
It was connected with presenter.
You need to present MFMailComposeViewController from UINavigationController.
Try this:
self.navigationController.presentViewController(mail, animated: true, completion: nil)
It solved my problem.
If you check the value of MFMailComposeViewController.canSendMail(), you will see that it is false. So that the code inside your if statement would not get executed.
And to return true, you need to enable one email on your mobile phone.
You need to Login in 'Mail' App in order to present the Mail Composer.
For me this answer solved the problem. I had the same issue on a real device with active mail accounts and changed the presenting view controller to
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients([address])
mailComposeViewController.setMessageBody(message, isHTML: false)
mailComposeViewController.setSubject(subject)
UIApplication.shared.keyWindow?.rootViewController?.present(mailComposeViewController, animated: true)
#IBAction func gmailButton(_ sender: UIButton){
self.popUp()
}
func popUp(){
guard MFMailComposeViewController.canSendMail() else {
return
}
let composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
composer.setToRecipients(["helpdesk#gmail.com"])
composer.setSubject("succes")
composer.setMessageBody("succes sent", isHTML: false)
present(composer, animated: true)
}
First you have to log in to Gmail, after that this program can be used.
don't forget use real device to try this

UIActivityViewController - Facebook, works perfectly on simulator, but not on a device

When I run through the Xcode simulator, I can post both a picture and a url. One a device, however, I get an entirely different dialog.
I've used another example on here to illustrate the code
let myWebsite = NSURL(string:"http://www.google.com/")
let img: UIImage = imageView.image!
guard let url = myWebsite else {
print("nothing found")
return
}
let shareItems:Array = [img, url]
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
self.presentViewController(activityViewController, animated: true, completion: nil)
On the simulator, the dialog comes up perfectly, and it posts both the picture and url to Facebook.
When I run the exact same example on my phone, a totally different dialog comes up, where I'm asked to add a line ("say something about this") and then it posts this headline, along with the google url
Interestingly enough, on the simulator, the url is posted as a url in Facebook, on the device, it's posted as a hyperlink.
Ultimately, I would like the the image and the hyperlink to appear on Facebook. However, if I was able to get the image and the url to post, I would be thrilled.
Has anyone had similar experiences?

Deep link not working for a case

Hey I am developing an app for the version iOS7 and above, where I have to share a content via mail or message. I use the following code
let textToShare = "Just click the following link to view "
let urlToShare = NSURL(string: "croding.com://crodid/crodname")
let objectsToShare = [textToShare, urlToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
I have added the croding.com in plist. Its working fine (open our app from mail exactly what I want) only if the app is installed already otherwise this thing is just a text instead of link. I need to show it as link even app is not installed.
croding.com://crodid/crodname