Skip to content

Instantly share code, notes, and snippets.

@jjaffeux
Created September 4, 2012 22:47
Show Gist options
  • Save jjaffeux/3627617 to your computer and use it in GitHub Desktop.
Save jjaffeux/3627617 to your computer and use it in GitHub Desktop.
sharemotion_readme.md

Sharemotion

Overview

Sharemotion, is a lightweight gem for RubyMotion. It provides functions to share text, urls,… on social networks or messages. If you need a full featured library you should use ShareKit.

Setup

Strong and Emphasize

Loot at the rakefile and the demo app for fast example

  1. Add facebook plist informations (Rakefile)
app.info_plist['CFBundleURLTypes'] = [{'CFBundleURLSchemes' => ['fbxxxxxxxxxxxxx']}]
app.info_plist['FacebookAppID'] = "xxxxxxxxxxxxx"
  1. Add facebook sdk through pods (Rakefile)
app.pods do
  pod 'Facebook-iOS-SDK'
end
  1. Add frameworks (Rakefile)
app.frameworks += ['MessageUI', 'Twitter']
  1. gem install sharemotion

  2. require 'sharemotion' (Rakefile)

Usage

Getting started

# create the item you want to share
# the basic item can have :title, :url, image(string url), :text, you can override the hash for each sharers
# some sharers have specific fields and some won't use all the base fields, described later

@item = Sharemotion::Item.new({
  :title => "Look at that bro!",
  :url => "http://www.google.fr",
  :image => "http://www.aujardin.ch/photos/tulipe1.jpg",
  :text => "You should watch this site, it's incredible",
  :sharers => {
    :email => {
      :to => ["[email protected]", "[email protected]"],
      :text => "Well you shouldn't..."
    },
    :facebook => {
      :caption => "OHAI",
      :title => "HEY HEY"
    }
  }
})


# define sharers you want to use
# you can override the title of the sharer with a block 
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item) {|sharer|
  sharer.sharer_title = "Bookface"
}

sharers = [
  Sharemotion::SHMEmail.alloc.initWithItem(@item),
  Sharemotion::SHMSms.alloc.initWithItem(@item),
  Sharemotion::SHMTwitter.alloc.initWithItem(@item),
  facebook
]

# Init the UIActionSheet with your sharers and display it
@sheet = Sharemotion::Sheet.alloc.initWithSharers(sharers, controller:self)
@sheet.showInView(self.view)

# You can also use a sharer directly
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item) 
facebook.share(self)

Documentation on sharers

  • SHMEmail will use :text(string), :title(string), :html(boolean), :cc(array), :bcc(array), :to(array)

  • SHMFacebook will use :url(string), :image(string), :caption(string), :title(string), :text(string)

  • SHMSms will use :text(string), to(array)

  • SHMtwitter will use :text(string), :url(string)

As you can see email and sms accept :to, however, email wants… emails and sms wants phonenumbers so if you want to use both of them with right data you have to use the override hash explained before :

@item = Sharemotion::Item.new({
  :title => "Look at that bro!",
  :url => "http://www.google.fr",
  :image => "http://www.aujardin.ch/photos/tulipe1.jpg",
  :text => "You should watch this site, it's incredible",
  :sharers => {
    :email => {
      :to => ["[email protected]", "[email protected]"],
    },
    :sms => {
      :to => ["06XXXXXXXX", "07XXXXXXXX"]
    }
  }
})

Todo

Better documentation

More tests

More sharers

Twitter < IOS 5.0

Do not require Facebook SDK if you don't use Facebook sharer

Same for frameworks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment