How to share image with text in Facebook SDK in swift - ios

I want to share a post on facebook with Image and text. I am using Facebook SDK and I am able to share Image, Now I want to share text with this image. How I can?
Here is the source code of sharing the image,
let photo:FBSDKSharePhoto = FBSDKSharePhoto()
var message:String?
let imageName:String = "Star.png"
photo.image = UIImage(named: imageName)
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo];
let dialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = content
dialog.mode = .native
dialog.show()

Due to the abuse from some applications, Facebook has explicitly disabled the pre-fill option for the text by simply ignoring it.
"You must not pre-fill any of the fields associated with the
following products, unless the user manually generated the content
earlier in the workflow: Stream stories (user_message parameter for
Facebook.streamPublish and FB.Connect.streamPublish, and message
parameter for stream.publish), Photos (caption), Videos (description),
Notes (title and content), Links (comment), and Jabber/XMPP."
More info here.

Facebook wont allow user to add text with image.
Integrate facebookshare sdk
#IBAction func facebookBtn(sender: AnyObject) {
let shareImage = SharePhoto()
shareImage.image = imageView.image //Image from your imageview
shareImage.isUserGenerated = true
let content = SharePhotoContent()
content.photos = [shareImage]
let sharedDialoge = ShareDialog()
sharedDialoge.shareContent = content
sharedDialoge.fromViewController = self
sharedDialoge.mode = .automatic
if(sharedDialoge.canShow)
{
sharedDialoge.show()
}
else
{
print("Install Facebook client app to share image")
}
}

Try this :
let sharePhoto = FBSDKSharePhoto()
photo.image = photo
photo.caption = "you title"
let content = FBSDKShareMediaContent()
content.media = [photo];

Related

Check PDF Content Size and show alert Swift

Is there any way to find the current pdf content size.
For example:-
When user open the pdf file and fill some information in the pdf and click on submit button. Then how to check pdf content size means the content fill fully or not. If user not fully added the details, pending some TextFiled in the pdf, then we need to show alert "Please fill all the information."
Code:-
override func viewDidLoad() {
super.viewDidLoad()
if let documentURL = Bundle.main.url(forResource: pdfName, withExtension: "pdf") {
if let document = PDFDocument(url: documentURL) {
pdfView.autoScales = true
pdfView.backgroundColor = UIColor.lightGray
document.delegate = self
pdfView.document = document
pdfView.autoScales = true
}
}
}
Can someone please explain to me is it possible in swift if yes please guide me how to achieve this, I've tried lot of search but no results yet.
Any help would be greatly appreciated.
Thanks in advance.
I found solution to check PDF Content.
Code:-
func checkPDFTextFiledDataBlankOrNot() {
if let page = pdfVw.document?.page(at: 0){
let annotations = page.annotations
for annotation in annotations{
if annotation.widgetStringValue == " "{
annotation.widgetStringValue = "N/A"
emptyTxtFields += 1
}else {
fillTxtfields += 1
}
}
}
}

Swift 5 or up - Image view on pickerview

My images from "2.jpg" to "7.jpg" shows but the first image("1.jpg") on my simulator. what do I need to change?
var imageFileName = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg"]
for i in 0 ..< MAX_ARRAY_NUM {
let image = UIImage(named: imageFileName[i])
imageArray.append(image)
lblImageFileName.text = imageFileName[0]
imageView.image = imageArray[0]
enter image description here
enter image description here
I think you should change below two lines
lblImageFileName.text = imageFileName[0]
imageView.image = imageArray[0]
to,
lblImageFileName.text = imageFileName[i]
imageView.image = imageArray[i]
as you used variable i to represent index

NSTextAttachment() Extra Properties

I am wanting to add extra info onto some of the images I add to my UITextView. The class is NSTextAttachment(). I need my images to have some String descriptions so the app knows what's inside the image. How do I add this extra functionality? Is it through an Extension?
let attachment = NSTextAttachment()
attachment.image = image
attachment.bounds = CGRect(origin: .zero, size: image.size)
// Extra properties wanted
attachment.description = "add in info about what is in attachment"
attachment.moreInfo = "some more info about the attachment"
class EmojiTextAttachment:NSTextAttachment{
}
private var EmotagAssociationKey:String? = nil
extension EmojiTextAttachment{
var emoticonName:String?{
get {return objc_getAssociatedObject(self,&EmotagAssociationKey) as? String ?? ""}
set {objc_setAssociatedObject(self, &EmotagAssociationKey, newValue, .OBJC_ASSOCIATION_RETAIN) }
}
}
It's been a while, but my solution is up.
Extends NSTextAttachment
You can add parameters with objc_getAssociatedObject and objc_setAssociatedObject
When using it, use EmojiTextAttachment instead of NSTextAttachment.
let emoticon:EmojiTextAttachment = EmojiTextAttachment()
let image = UIImage(named: myImage) as UIImage!
emoticon.image = image?.resizeSelf(newWidth, newHeight)
emoticon.emoticonName = emoname
The docs of objc_getAssociatedObject https://developer.apple.com/documentation/objectivec/1418865-objc_getassociatedobject

Swift : Avatar image is mandatory in swift code

By default "no-profile-image" is set to imageview, User should upload the profile picture mandatory while registration, otherwise user should not allow to navigate to next screen.Any help is appreciable.
Here is my code
lazy var profileLogo:UIImageView = {
let profileLogo = UIComponentFactory.appImageView(UIImage(named: "no-profile-image")!, contentMode: .ScaleToFill, cornerRadius: LayoutService.width(15))
profileLogo.userInteractionEnabled = false
return profileLogo
}()
func nextButtonPressed() {
let noImage = UIImage(named: "no-profile-image")
if self.mainView.profileLogo.image == nil && self.mainView.profileLogo.image == noImage{
displayAlert("", message: "profile picture is mandatory, please upload it")
}
}

loading playlist artwork like in the music app

I'm looking for an solution to display my artwork like in the apple music application. I'm able to load one artwork for the playlist but I want to be able to show 4 of the artworks as a playlist representative.
Currently I'm using this code for my playlist view
let objects = items.objectAtIndex(indexPath.item) as! MPMediaItemCollection
let repObjects = objects.representativeItem
cell.lbl_Name.text = objects.valueForProperty(MPMediaPlaylistPropertyName) as? String
let artwork = repObjects?.valueForProperty(MPMediaItemPropertyArtwork)
let artworkImage = artwork?.imageWithSize(CGSize(width: 130, height: 130))
if(artworkImage != nil){
cell.img_artwork.image = artworkImage
}
else{
cell.img_artwork.image = UIImage(named: "no_Artwork.png")
}
What would be the best way to go at this

Resources