iOS Tutorial Share data from your app with ActivityViewController

Discussion in 'iOS Tutorials' started by Erel, Nov 17, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    upload_2016-11-17_9-57-25.png

    ActivityViewController allows the user to share data from your app using the standard share dialog.
    It was added in iPhone library v2.00.

    Using it is simple. You need to initialize AVC with one or more items that you want to share and call show:
    Code:
    Sub Page1_Click
       
    Dim avc As ActivityViewController
       avc.Initialize(
    "avc"Array("Some text to share together with an image"LoadBitmap(File.DirAssets, "smiley.png")))
       avc.Show(Page1, Page1.RootPanel) 
    'Second parameter is relevant for iPad only. The arrow will point to the view.
    End Sub

    Sub avc_Complete (Success As Boolean, ActivityType As String)
       
    Log($"Success: ${Success}, ActivityType: ${ActivityType}"$)
    End Sub
    You can also share files with ActivityViewController.

    Code:
    Sub Page1_Click
       
    Dim avc As ActivityViewController
       avc.Initialize(
    "avc"Array(CreateFileUrl(File.DirLibrary, "1.pdf")))
       avc.Show(Page1, Page1.RootPanel)
    End Sub

    'Doesn't work with assets files. You must first copy them.
    Sub CreateFileUrl (Dir As String, FileName As StringAs Object
       
    Dim no As NativeObject
       no = no.Initialize(
    "NSURL").RunMethod("fileURLWithPath:"Array(File.Combine(Dir, FileName)))
       
    Return no
    End Sub

    Sub avc_Complete (Success As Boolean, ActivityType As String)
       
    Log($"Success: ${Success}, ActivityType: ${ActivityType}"$)
    End Sub
     
  2. moore_it

    moore_it Active Member Licensed User

    Thanks Erel, wonderful job !
     
  3. tufanv

    tufanv Expert Licensed User

    Perfect !
     
  4. sorex

    sorex Expert Licensed User

    nice, Erel.

    I assume that this is from now on the official method and replaces that modShare.bas module someone posted here once?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    This is part of the official libraries. Whether you want to use it or use the previous module is up to you to decide...
     
  6. Descartex

    Descartex Well-Known Member Licensed User

    Absolutely amazing and easy to work with!
    Thank you so much!!!
     
  7. ilan

    ilan Expert Licensed User

    Wow this is perfect. exactley what i need for one of my app. thanx a lot !
     
  8. b4xscripter

    b4xscripter Member Licensed User

    Hi!
    Many thanks for this library!
    For my project I would like to have an easy action: when is performed a Sub, for example, Activity_Create, it should just open a dialog listing all the possible "social networks" and email to share the text. Nothing more. On Android is very easy:

    Code:
    Sub Globals
    'Android code
    Private
    intent As INTENTID
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layout1")
    intent.Initialize
    intent.ShareText("HOLA!!!!")
    End Sub
    I suppose that it should be something like:

    Code:
    Sub Activity_Create(FirstTime As Boolean)
    Dim avc As ActivityViewController
     avc.Initialize(
    "avc"Array("Some text to share together with an image"LoadBitmap(File.DirAssets, "smiley.png"))) ' I only want to share the text, nothing more!
     avc.Show(Page1, Page1.RootPanel) 'Second parameter is relevant for iPad only. The arrow will point to the view.
    End Sub
    Could someone clarify that this library is right for my this purpose?

    Thank you!
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the questions forum.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice