Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by OJ3D · Jul 18, 2016 at 02:40 AM · facebookboolobjective-cunity plugin

Objective-C Value to C wrapper - Unity Plugin (ios app check)

Hey all, need some quick help with my objective-c plugin. All it does it check to see if Facebook or yelp is installed.

The problem is, I'm not familiar with Objective-C or retrieving the value in the extern C wrapper. see my code below.

I appreciate any help provided. Thanks y'all,

  //
     //  UnityPluginTest-1.mm
     //  
     //  Created by OJ on 7/13/16.
     //
   #import <Foundation/Foundation.h>    
     @interface SampleClass:NSObject
     /* method declaration */
     - (BOOL)isYelpInstalledX;
     - (BOOL)isFBInstalledX;
     @end
     
     @implementation SampleClass
     
         - (BOOL)isYelpInstalledX {
              return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yelp://"]];
         }
     
         - (BOOL)isFBInstalledX {
             return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]];
         }
     
     @end
     
     extern "C"
     {
         bool isFBInstalled(){
                     
           // Need to get the Objective C BOOL value from above, my c# script will read get this value once retrieved
          
        
          //return -(Bool) isFBInstalledX value  //--this doesn't work
          //return ..... // I give up  :(
     
         }
         
         bool isYelpInstalled(){
             
             return false;
       }
     }
        

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by OJ3D · Jul 20, 2016 at 01:52 PM

Finally got the answer!

First - Apparently apple now requires you to place the URL schemes you're planning to call in your info.plist -

"If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array." - here's that resource Apple UIApplication-canOpenURL

In this case my strings would be fb, and yelp.

Second, feel free to use my attached scripts:

  • UnityPluginTest-1.mm (put this in your "Assets>plugins>ios" folder)UnityPluginTest-1.mm

  • GetMyOjbectiveCUnityPlugin.cs ( this is the bridge. Place this in the same folder)GetMyOjbectiveCUnityPlugin.cs

  • delete the "txt" portion in the file extension to get them to work

To call the FB/Yelp status from a script of your own you can do:

int testfb = GetMyOjbectiveCUnityPlugin().WegotFBApp(); //0 is No, 1 yes

int testyelp = GetMyOjbectiveCUnityPlugin().WegotYelpApp(); //0 is No, 1 yes

FYI - I have a similar response in another Unity Forum - Objectiv-C to Unity Plugin ios app Status - OJ3D)

Cheers, OJ


unityplugintest-1mm.txt (1.5 kB)
getmyojbectivecunityplugincs.txt (1.3 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OJ3D · Jul 20, 2016 at 02:43 PM 0
Share

If you get a value of 20,40 for the status's that still means a "NO". I accidentally left them there from an earlier test. You can spot those "param" values in the "UnityPluginTest-1.mm" file and update them to 0 if you'd like within their respective Objective-C methods.

$$anonymous$$y forum version has those values updated - ObjC-UnityPlugin-AppStatus

Anyone wanting to do the plist pre-loaded so you don't have to do it manually try these xcode techniques from unity -https://community.unity.com/t5/Unit...Xcode-project-targets-Info-plist/td-p/2235796

Also here's a list of popular URL schemes: http://wiki.akosma.com/IPhone_URL_Schemes

avatar image chilemanga · Apr 11, 2018 at 08:08 PM 0
Share

Thank you very much for the detailed responses and sharing. However, there's no need to add "fb" as an URL scheme to open facebook app. If you add that to your Info.plist, the device will open "fb://" links with your app, so be careful.

avatar image
0

Answer by OJ3D · Jul 19, 2016 at 07:09 PM

The following is as far as I got to, unfortunately it's returning as false when fb & yelp are actually both installed on my device:

      //  UnityPluginTest-1.mm
      //  Created by OJ on 7/13/16.
      //In unity, You'd place this file in your "Assets>plugins>ios" folder

    //Objective-C Code
    #import <Foundation/Foundation.h>    
      @interface SampleClass:NSObject
      /* method declaration */
      + (BOOL)isYelpInstalledX;
      + (BOOL)isFBInstalledX;
      @end
      
      @implementation SampleClass
      
          + (BOOL)isYelpInstalledX {
               return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yelp://"]];
          }
         + (BOOL)isFBInstalledX {
              return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]];
          }
      @end
 
     //C-wrapper that Unity communicates with
      extern "C"
      {
          bool isFBInstalled(){                     
            // Need to get the Objective C BOOL value from above, my c# script will read get this value once retrieved        
         return [SimpleClass isFBInstalledX]; //Tested with a build but not returning the true status, also not sure if it's bc it's a BOOL vs a bool
          }
          
          bool isYelpInstalled(){
 
        // Need to get the Objective C BOOL value from above, my c# script will read get this value once retrieved 
        return [SimpleClass isYelpInstalledX ]; //Tested with a build but not returning the true status, also not sure if it's bc it's a BOOL vs a bool
        }
      }

Anyone wondering what the C# script that calls this .mm Obj-c, it looks like this:

  using UnityEngine;
   using System.Runtime.InteropServices;
  
     class GetMyOjbectiveCUnityPlugin : MonoBehaviour {
  
        #if UNITY_IOS || UNITY_XBOX360
  
        // On iOS and Xbox 360 plugins are statically linked into
        // the executable, so we have to use __Internal as the
        // library name.
        [DllImport ("__Internal")]
     private static extern bool isFBInstalled();
        [DllImport ("__Internal")]
     private static extern bool isYelpInstalled();
  
        #else
  
        // Other platforms load plugins dynamically, so pass the name
        // of the plugin's dynamic library.
        [DllImport ("PluginName")]
  
        #endif
  
        void Awake () {
   
        //Assign value we receive to these
        bool FBStatus;
        bool YelpStatus; 
  
           // Calls the isFBInstalled function inside the plugin 
        FBStatus = isFBInstalled(); //returns the status if FB installed on ios device in ObjC plugin
       YelpStatus= isYelpInstalled();//returns the status if Yelp installed on ios device in ObjC plugin
  
        }
     }

Anyway, still stuck with getting nothing back. :(

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by OJ3D · Jul 20, 2016 at 01:52 PM

Finally got the answer!

First - Apparently apple requires you to place the URL schemes you're planning to call in your info.plist - "If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array." - here's that resource Apple UIApplication-canOpenURL In this case my strings would be fb, and yelp.

Second, feel free to use my attached scripts ( I put them in another Unity Forum - Objectiv-C to Unity Plugin ios app Status - OJ3D)

  • UnityPluginTest-1.mm (put this in your "Assets>plugins>ios" folder)

  • GetMyOjbectiveCUnityPlugin.cs ( this is the bridge. Place this in the same folder)

To call the FB/Yelp status from a script of your own you can do: int testfb = GetMyOjbectiveCUnityPlugin().WegotFBApp(); //0 is No, 1 yes int testyelp = GetMyOjbectiveCUnityPlugin().WegotYelpApp(); //0 is No, 1 yes

Cheers, OJ

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS Facebook integration issue. 0 Answers

Facebook sdk for ios 9 is not opening the app when logging in, Why? 1 Answer

Do our company need a Facebook business account for integrating our unity game? 1 Answer

Facebook SDK Login Loads for a long time 0 Answers

Unity Facebook SDK Login in using FB app rather than Safari browser 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges