Module: MotionSocial::Sharing
- Defined in:
- lib/project/motion-social.rb
Instance Method Summary collapse
- #actionSheet(actionSheet, clickedButtonAtIndex: buttonIndex) ⇒ Object
- #display_share_dialog(sender = nil) ⇒ Object
- #error_message_for(service) ⇒ Object
- #post_to_facebook ⇒ Object
-
#post_to_twitter ⇒ Object
Usage: include MotionSocial::Sharing.
Instance Method Details
#actionSheet(actionSheet, clickedButtonAtIndex: buttonIndex) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/project/motion-social.rb', line 61 def actionSheet(actionSheet, clickedButtonAtIndex:) puts if == 1 post_to_facebook elsif == 0 post_to_twitter end end |
#display_share_dialog(sender = nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/project/motion-social.rb', line 52 def display_share_dialog(sender=nil) action_sheet = UIActionSheet.alloc.init action_sheet.delegate = self action_sheet.addButtonWithTitle "Twitter" action_sheet.addButtonWithTitle "Facebook" action_sheet.cancelButtonIndex = action_sheet.addButtonWithTitle("Cancel") action_sheet.showInView(self.controller.view) end |
#error_message_for(service) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/project/motion-social.rb', line 45 def (service) = UIAlertView.alloc.initWithTitle("Something is wrong", message:"You don't have #{service} configured. Please go to your phone's settings and configure it.", delegate:nil, cancelButtonTitle:"OK", otherButtonTitles:nil) .show end |
#post_to_facebook ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/project/motion-social.rb', line 33 def post_to_facebook if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) sheet = SLComposeViewController.composeViewControllerForServiceType(SLServiceTypeFacebook) sheet.setInitialText() url = NSURL.alloc.initWithString(sharing_url) sheet.addURL(url) controller.presentViewController(sheet,animated:true,completion:nil) else ("Facebook") end end |
#post_to_twitter ⇒ Object
Usage: include MotionSocial::Sharing
define the following methods:
def sharing_message def sharing_url def controller
When you want to display the sharing dialogs just use:
postToTwitter(sender) postToFacebook(sender)
or display a dialog with Facebook and Twitter as options:
display_share_dialog
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/project/motion-social.rb', line 21 def post_to_twitter if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) tweetSheet = SLComposeViewController.composeViewControllerForServiceType(SLServiceTypeTwitter) tweetSheet.setInitialText() url = NSURL.alloc.initWithString(sharing_url) tweetSheet.addURL(url) controller.presentViewController(tweetSheet,animated:true, completion:nil) else ("Twitter") end end |