ios swift FBSDKShareKit Publish (Share) content without ShareDialog view controller - swift

i want to put function with "sharing facebook" when "user start live"
if that Fb Button is on then user touches that Live Button,
the content will publish on user's timeline on facebook automatically, then start "Live Broadcasting"
so the ShareDialog will not be present up.
but if ShareDialog should be presented for permission,
i want to do it when user touches that fb button.
======== ref
https://developers.facebook.com/docs/sharing/opengraph/ios
var content = FBSDKShareLinkContent()
content.contentURL = URL.init(string: "https://www~")
content.hashtag = FBSDKHashtag(string: "#ABCDE")
// content.contentTitle = self.broadcastingInfo.title ?? ""
// content.imageURL = self.broadcastingInfo.image
// var shareDialog = FBSDKShareDialog()
// shareDialog.shareContent = content
// shareDialog.mode = .native
// try shareDialog.show()
// do not want shareDialog
FBSDKShareAPI.share(with: content, delegate: self)
// error : The operation couldn’t be completed. (com.facebook.sdk.core error 8.)

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()

Change iOS 10 notification image thumbnail size

I'm new to Xcode and Swift. I'm tying to send a local notification with an image shown. I use UNNotificationAttachment to attach an image from the following code:
let content = UNMutableNotificationContent()
content.title = "Testing"
content.body = "Testing rich notification"
let attachement = try! UNNotificationAttachment(identifier: "image", url: Bundle.main.url(forResource: "myImg", withExtension: "png")!, options: nil)
content.attachments = [attachement]
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "TenSecond", content: content, trigger: trigger) // Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error : Error?) in
if error != nil {}
}
I can see a thumbnail on the right side of the notification banner, but it's too small. I want to increase the size of the thumbnail so the notification look like this:
Notification With larger thumbnail
Is it possible?
No, it's not possible, iOS determines the max size.
With iOS 10 you could use the UserNotificationsUI framework to replace the notification body with one that has a larger UIImageView for the thumbnail.
See Customizing the Appearance of Notifications for details.

how to create user interactive tweet or Facebook post with UIActivityViewController

I am trying to figure out how to create a user interactive post or tweet kind of like SoundCloud's here below:
The portion highlighted in yellow is the part that interests me because as far as I can tell when it comes to UIActivityViewController (which is what Sound Cloud uses for this) the only objects that work for sharing are images and strings.
Further more, if you were to tap the portion highlighted in yellow this screen would pop up on twitter:
HOW DO THEY DO THAT!? THEY HAVE A PAUSE BUTTON AND EVERYTHING!
This is my attempt to do that...
func displayShareSheet(shareContent:String) {
let someView:CustomView = CustomView() // CustomView is a subclass of UIView
let activityViewController = UIActivityViewController(activityItems: [someView], applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: {})
}
...which doesn't work. The UIActivityViewController sheet pops up with no share options indicated.
I understand that some may consider this a broad question but if you could at least point me in the right direction I would be very grateful. Thank You.
This works. For the full list of sharing destinations run it on your device and not the simulator. The simulator gives you a smaller list.
func createActivityController() -> UIActivityViewController {
let someText:String = textView.text
let google = NSURL(string:"http://google.com/")!
// let's add a String and an NSURL
var activityViewController = UIActivityViewController(
activityItems: [someText, google],
applicationActivities: nil)
activityViewController.completionHandler = {(activityType, completed:Bool) in
if !completed {
print("cancelled")
return
}
if activityType == UIActivityTypePostToTwitter {
print("twitter")
}
if activityType == UIActivityTypeMail {
print("mail")
}
}
// you can specify these if you'd like.
// activityViewController.excludedActivityTypes = [
// UIActivityTypePostToTwitter,
// UIActivityTypePostToFacebook,
// UIActivityTypePostToWeibo,
// UIActivityTypeMessage,
// UIActivityTypeMail,
// UIActivityTypePrint,
// UIActivityTypeCopyToPasteboard,
// UIActivityTypeAssignToContact,
// UIActivityTypeSaveToCameraRoll,
// UIActivityTypeAddToReadingList,
// UIActivityTypePostToFlickr,
// UIActivityTypePostToVimeo,
// UIActivityTypePostToTencentWeibo
// ]
return activityViewController
}
For the first part it's only play button that clicks you to popup the player view.
Second: You can do this by just popping a new viewController, use any popup pod: CWPOP as ex. Or whatever suits you or as Twitter here i'm not sure but probably they're doing their own, and you just build a normal view which has the play and everything.
They used do it better before and let you play the music during going through tweets, that was way better to me at least.

FBSDKSharePhoto not sharing link alongside photo using 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.

My activity indicator is not appearing

I want to show an activity indicator after the user enters login credentials and clicks the login button. This seemed straight forward but the indicator is not showing when I run (build succeeded). I am not sure if this is because when the app runs for real, it will be passing the credentials up to a server for verification but that code is not active yet, so the login is instantaneous, or if I have written this wrong but not to cause an error. Thank you for your help.
#IBAction func loginButtonTapped(sender: AnyObject) {
//add error checking for loginEntered and passwordEntered if they are blank
if loginEntered.text == "" || passwordEntered.text == "" {
//Define the variable error for the message that should be displayed
self.alertError = "Please enter your Login ID and/or Password"
}
if self.alertError != "" { //if there is an error with the login
//Display the error message on screen
self.displayAlert("Missing Required Information", error: alertError)
//reset error variable
self.alertError = ""
//return the user to the LoginID field and empty it if there is data in it. Empty the password field too. ?? How do I do that??
} else { //the login ID and password are entered
//setup for a spinner to notify the user the app is working on something
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 80, 80))
activityIndicator.center = self.view.center;
activityIndicator.backgroundColor = (UIColor(white: 0.3, alpha: 0.5)) //creates a background behind the spinner
activityIndicator.layer.cornerRadius = 10
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
The code goes on to several if statements based on the login credentials and returning data from the server. Finally, is stops ignoring interaction events. Finally, I put this same code into an IBAction for a button I created to test the code. It works for the button.
Your code is fine or rather I would say it works, as mention is because the process takes milliseconds and not persives, I recommend that you put breakpoints in your code so that when you press Build can view the interaction to steps in your code.