Garret Kaye
Garret Kaye

Reputation: 2562

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:

(Shared directly from Sound Cloud)

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:

enter image description here

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.

Upvotes: 12

Views: 304

Answers (2)

Abdoelrhman
Abdoelrhman

Reputation: 916

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.

Upvotes: 2

Gene De Lisa
Gene De Lisa

Reputation: 3838

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
}

Upvotes: 2

Related Questions