Search Unity

iOS 6 Share Menu

Discussion in 'iOS and tvOS' started by MythicalCity, Jan 23, 2013.

  1. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Hi, anyone know how to display the iOS 6 share menu/screen (with Facebook, Twitter, Email, Message, etc icons)?
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    you need a plugin, it's the only way. Prime31 is the only one I can think of off the top of my head, that might be selling a plugin to do this. If you want to write it yourself, then you need to import the social framework into xcode. Then make an extern c method create/present an SLComposeViewController object. It's really only a few lines of code, if you know how to do it...
     
  3. @LSharp

    @LSharp

    Joined:
    Jan 24, 2013
    Posts:
    3
    @capitalJmedia, You can write your own plugin like this


    Unity side:

    Code (csharp):
    1.  
    2. // LSNativeCall.cs
    3.  
    4. using UnityEngine;
    5. using System.Collections;
    6. using System.Runtime.InteropServices;
    7.  
    8. public class LSNativeCall
    9. {
    10.     [DllImport("__Internal")]
    11.     private static extern void UIActivityVC(string text);
    12.        
    13.     public static void ShowUIActivityVC(string text)
    14.     {
    15.         #if UNITY_IPHONE
    16.             UIActivityVC(text);
    17.         #endif
    18.     }  
    19. }
    20.  
    Code (csharp):
    1.  
    2. //TestNativeCall.cs
    3. //for testing, attach to any MonoBehaviour
    4.  
    5. using UnityEngine;
    6. using System.Collections;
    7.  
    8. public class TestNativeCall : MonoBehaviour {
    9.  
    10.     void OnGUI(){
    11.         if (GUI.Button(new Rect(10,10,100,50),"Show")){
    12.             LSNativeCall.ShowUIActivityVC("Hello from Unity!");
    13.         }
    14.  

    XCode Side:

    Code (csharp):
    1.  
    2. //LSNativeCall.mm
    3.  
    4. #import "LSNativeManager.h"
    5. extern "C" {
    6.  
    7.     void UIActivityVC(char* text){
    8.         [[LSNativeManager sharedInstance] UIActivityVC:[NSString stringWithUTF8String:text]];
    9.     }
    10.    
    11. }

    Code (csharp):
    1.  
    2. //LSNativeManager.h
    3.  
    4. #import <Foundation/Foundation.h>
    5.  
    6. @interface LSNativeManager : NSObject
    7.  
    8. +(LSNativeManager*)sharedInstance;
    9. -(void)UIActivityVC:(NSString*)_text;
    10.  
    11. @end
    12.  
    Code (csharp):
    1.  
    2. //LSNativeManager.m
    3.  
    4. #import "LSNativeManager.h"
    5.  
    6. @implementation LSNativeManager
    7.  
    8. static LSNativeManager *sharedInstance = nil;
    9.  
    10. -(void)UIActivityVC:(NSString*)_text{
    11.    
    12.     NSArray *activityItems = @[_text];
    13.        
    14.     UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:Nil];
    15.     id rootVC = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
    16.     [rootVC presentViewController:activityVC animated:TRUE completion:nil];
    17. }
    18.  
    19. #pragma mark Singleton Methods
    20. + (id)sharedInstance {
    21.     @synchronized(self) {
    22.         if(sharedInstance == nil)
    23.             sharedInstance = [[super allocWithZone:NULL] init];
    24.     }
    25.     return sharedInstance;
    26. }
    27.  
    28. + (id)allocWithZone:(NSZone *)zone {
    29.     return [[self sharedInstance] retain];
    30. }
    31.  
    32. - (id)copyWithZone:(NSZone *)zone {
    33.     return self;
    34. }
    35.  
    36. - (id)retain {
    37.     return self;
    38. }
    39.  
    40. - (unsigned)retainCount {
    41.     return UINT_MAX;
    42. }
    43.  
    44. - (oneway void)release {
    45.  
    46. }
    47. - (id)autorelease {
    48.     return self;
    49. }
    50. - (id)init {
    51.     if (self = [super init]) {
    52.        
    53.     }
    54.     return self;
    55. }
    56. - (void)dealloc {
    57.     [super dealloc];
    58. }
    59.  
    60. @end
    61.  
     
    Guhanesh, vmelwani, Heykinox and 2 others like this.
  4. fedor.shubin

    fedor.shubin

    Joined:
    Oct 12, 2014
    Posts:
    3
    I created a small package that allows to easily integrate such kind of solution to your games. It's available for free at: https://github.com/vedi/share-bunch-unity3d. It supports Android as well.

    Any feedback is appreciated.
     
    Dreeka and forneed like this.
  5. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    Hi I tried your package but it gives loads of errors from Genericmethods0.cpp in xCode Thanks
     
    Last edited: Feb 2, 2016