FBSDKSharePhoto not sharing link alongside photo using Swift - swift

When I try to share a link along with a picture, at the same time, via FBSDKSharePhoto, only the photo gets shared. No link appears.
Here is the code I use:
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = self.scaledImage
photo.userGenerated = true
let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
content.contentURL = NSURL(string: self.short_string)
content.photos = [photo]
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
And a picture of the resulting dialog when I push the button: http://imgur.com/mZ483i9 (also attached)
You can see the picture gets attached to the post, but there is no link. I know all of the URL/Photo variables work fine because they are used elsewhere.
If I switch the sharing method to FBSDKShareLinkContent then content.contentURL works fine, but I cannot post the picture this way because the picture is not hosted on the web, which is why I am using FBSDKSharePhotoContent. (The picture is taken within the app.)
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: self.short_string)
content.contentTitle = self.title_text
content.contentDescription = self.desc_text
content.imageURL = NSURL(string: "http://randomimage.jpg/")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
So I know my link is structured properly according to the contentURL protocol, and FBSDKSharePhotoContent conforms to the same functions as FBSDKShareLinkContent. No clue why it won't work.

Due to Facebook rules you can`t set non user generated text.

Related

iOS9 FBSDKShareDialog native sharing not completes a post to facebook

I have an app written in Swift3 for iOS9 which attempts to share a custom link with image and description to facebook. The inter-app switching Plist keys are configured correctly - the user is asked for permission to open facebook, then a native facebook post is created in FB app.
The issue is that upon tapping Post, the user is returned to my app, but the FB post does not complete. I see a little black screen with a progress indicator flash, but the user is returned to my app before the progress is filled. (Same progress indicator fills up when using "automatic" share mode within the app)
How to make sure that FBSDKShareDialog completes posting a link to facebook native app before returning to my app?
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "http://customurl.com/")
content.contentTitle = "Custom Title"
content.contentDescription = "Custom description"
if let imageUrlUnwrapped = imageUrl {
content.imageURL = URL(string: imageUrlUnwrapped)
}
let dialog = FBSDKShareDialog()
dialog.fromViewController = self;
dialog.shareContent = content;
let url = URL(string: "fbauth2://")
if UIApplication.shared.canOpenURL(url!)
{
dialog.mode = FBSDKShareDialogMode.native
}
dialog.show()

How to create url/link of a Location in Google Map which can be share to anyone using swift?

I have plotted a marker in a Google Map, now i want to share that location to my friends via url/link. how to create link of that location in swift.
The use of this is if my friends click on that url/link, it will take to that location in a Google Map. I dont have any idea about it. the below code shows how i created a marker:
let position = CLLocationCoordinate2DMake(latitude,longitude)
let location = GMSMarker(position: position)
location.icon = image
location.icon = self.imageWithImage(image, scaledToSize: CGSize(width: 30.0, height: 30.0))
location.title = "the photo is clicked here"
location.map = MapView
To launch Apple Maps or Google Maps you need to create an NSURL.
let targetURL = NSURL(string: "http://maps.apple.com/?q=FartCity")!
https://developers.google.com/maps/documentation/ios-sdk/urlscheme
let targetURL = NSURL(string: "comgooglemaps://?q=FartCity")!
Check that the user has the correct map app by checking if the url can be handled.
let isAvailable = UIApplication.sharedApplication().canOpenURL(targetURL)
open the url
UIApplication.sharedApplication().openURL(targetURL)

How to send audio file with image and caption in iMessage app for iOS 10?

I am creating iMessage app and trying to send audio or video file to other user.
Video file works and looks fine but its not working as expected with audio file.
My current code is:
let destinationFilename = mp3FileNames[i]
let destinationURL = docDirectoryURL.appendingPathComponent(destinationFilename)
if let conversation = activeConversation {
let layout = MSMessageTemplateLayout()
layout.image = UIImage.init(named: "audio-x-generic-icon")
layout.mediaFileURL = destinationURL
layout.caption = selectedSongObj.name
let message = MSMessage()
message.layout = layout
message.url = URL(string: "emptyURL")
conversation.insert(message, completionHandler: nil)
return
}
Looks like layout.mediaFileURL = destinationURL is not adding any file into message.
And when I try to send file with above code.It looks like shown below:
It looks fine but there is no audio to play but if I try this way:
let destinationFilename = mp3FileNames[i]
let destinationURL = docDirectoryURL.appendingPathComponent(destinationFilename)
if let conversation = activeConversation {
conversation.insertAttachment(destinationURL!, withAlternateFilename: nil, completionHandler: nil)
return
}
And result with above code is:
I can play audio for that message because it's there. But problem with that message is I can not attach any image or caption with it.
How can I attach image and audio file into same message.
And if possible instead of image can I add GIF?
Any help would be much appreciated, Thank you.
Not necessary to use GIF, iMessage extensions supports also PNGand JPEG image formats. Recommended image size is 300x300 points at #3x scale.
If the MSMessageTemplateLayout's image property has a non-nil value then
mediaFileURL property is ignored. So you can't send an image and an audio file at the same time. Docs

How to clear cache on UIWebView in swift?

I'm using tableview to display different pdfs locally. For example;
pdf1 -> "1.pdf"
pdf2 -> "2.pdf"
pdf3 -> "3.pdf"
In my first click, there is no problem but when I tap again it loads different pdf. Ex: I tap pdf2 but it loads pdf1.
Can you help me in this issue, I'm new to swift..
You can easily do it with ;
NSURLCache.sharedURLCache().removeAllCachedResponses()
NSURLCache.sharedURLCache().diskCapacity = 0
NSURLCache.sharedURLCache().memoryCapacity = 0
Also use like this;
let url = NSURL(string: "http://www.web.com")
let url_request = NSURLRequest(URL: url,
cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 5.0)
let webView = UIWebView()
webView.loadRequest(url_request)
Thanks

How to implement shareing in cocos2d-x

I am new cocos2dx developer.I am using the version cocos2dx 2.2.6.Now i want to share image on gmail and facebook.I refer many site and suggestion but still i am not clear about sharing.
We can use the UIActivityViewController to create a sharing dialog and use some CCRenderTexture code to take a screenshot. When the share button is tapped, a number of options for sharing are available depending on what applications the user has available on their phone.
You can create a sharing popup using the following code:
func openShareDialog() {
var scene = CCDirector.sharedDirector().runningScene
var node: AnyObject = scene.children[0]
var screenshot = screenShotWithStartNode(node as! CCNode)
let sharedText = "Text"
let itemsToShare = [screenshot, sharedText]
var excludedActivities = [ UIActivityTypeAssignToContact,
UIActivityTypeAddToReadingList, UIActivityTypePostToTencentWeibo]
var controller = UIActivityViewController(activityItems: itemsToShare, applicationActivities: nil)
controller.excludedActivityTypes = excludedActivities
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(controller, animated: true, completion: nil)
}
Then we can take a screenshot using a CCRenderTexture:
func takeScreenshotWithNode(node: CCNode) -> UIImage {
CCDirector.sharedDirector().nextDeltaTimeZero = true
var viewSize = CCDirector.sharedDirector().viewSize()
var rtx = CCRenderTexture(width: Int32(viewSize.width), height: Int32(viewSize.height))
rtx.begin()
node.visit()
rtx.end()
return rtx.getUIImage()
}
Here's an example of what the popup would actually look like when displayed:
You can find more information on the UIActivityViewController in Apple's docs.
You can might find it handy to start by reading the docs here.
There are additional detailed instructions in the cocos2d-x.org site including ones for iOS.