class UnderOs::Sharing

Constants

CUSTOM_RECEIVERS
NATIVE_RECEIVERS
VERSION

Public Class Methods

new(options={}) click to toggle source
# File lib/under_os/sharing.rb, line 5
def initialize(options={})
  @options = options
end

Public Instance Methods

controller_for(items) click to toggle source
# File lib/under_os/sharing/controller.rb, line 3
def controller_for(items)
  UIActivityViewController.alloc.tap do |controller|
    controller.initWithActivityItems(items, applicationActivities: custom_activities)
    controller.excludedActivityTypes = excluded_activities
  end
end
custom_activities() click to toggle source
# File lib/under_os/sharing/controller.rb, line 10
def custom_activities
  [].tap do |activities|
    CUSTOM_RECEIVERS.each do |key, receiver|
      activities << receiver.alloc.init if receivers_include(key)
    end
  end
end
excluded_activities() click to toggle source
# File lib/under_os/sharing/controller.rb, line 18
def excluded_activities
  [].tap do |activities|
    NATIVE_RECEIVERS.each do |key, receiver|
      activities << receiver unless receivers_include(key)
    end
  end
end
items_from(objects) click to toggle source
# File lib/under_os/sharing.rb, line 15
def items_from(objects)
  objects
end
receivers_include(key) click to toggle source
# File lib/under_os/sharing/controller.rb, line 26
def receivers_include(key)
  if @options.has_key?(:receivers)
    @options[:receivers].map(&:to_sym).incude?(key)
  elsif @options.has_key?(:exclude)
    ! @options[:exclude].map(&:to_sym).include?(key)
  else
    true # fallback to inclusion
  end
end
share(*objects, &block) click to toggle source
# File lib/under_os/sharing.rb, line 9
def share(*objects, &block)
  controller = controller_for(items_from(objects))
  UnderOs::App.history.current_page._
    .presentViewController(controller, animated: true, completion: block)
end