Compiling plugin for iOS - need more info.

I looked at these docs: http://unity3d.com/support/documentation/Manual/Plugins.html
But they really skim over it.

Exactly how do I compile an Objective-C function and get it to work in Unity? Is it something I do using Xcode? If so, how do I set up a project in Xcode to do it? When I compile, do I get a compiled file of some sort that I have to add to my Unity Assets?

Thanks.

this is how you a call a function declared in xcode

using UnityEngine;
using System.Collections;

    public class NativeMethod : MonoBehaviour {
    
    	[System.Runtime.InteropServices.DllImport("__Internal")]
    	extern static public int AwesomeFunction(int awesomeParameter);
        private int temp;
  
    	void OnGUI()
    	{
    		if(GUI.Button(new Rect(10*(Screen.width)/100,10*(Screen.height)/100,25*(Screen.width)/100,20*(Screen.height)/100),"CallNativeFunction"))
    		{
    			PlayerPrefs.SetInt("Save",0);
    			temp = AwesomeFunction(5);
    		}
    	}
    }

this is the code for the xcode side

AppController.h

#ifdef __cplusplus
extern "C" {
#endif
		
	int AwesomeFunction(int awesomeParameter);	
#ifdef __cplusplus
}
#endif

AppController.mm

    int AwesomeFunction(int awesomeParameter)
    {
    	// My awesome code goes here.
    	NSLog(@"Function pressed from unity with value %d",awesomeParameter);
    		
    	
    	if ([[NSUserDefaults standardUserDefaults] integerForKey: @"Save"] == 0)  //to read playerpref set from unity
    	{
    		NSLog(@"value recieved from unity for save with value 0");
    	}
    	
    	[[NSUserDefaults standardUserDefaults] setInteger: 42 forKey: @"Save"];  // set new value for playerpref

// you can call whichever plugin you want here in this function or if you want to return some value back to unity or whatever else you like

    	return 70;
    }

Hope this helps…

@ Gillissie : see there are two ways to create a plugin

1.Write a plugin in c based language compile it and then copy it to the plugin folder in your unity project and then call the methods as per your need

2 call a static extern function in unity,build the project,go to xcode created build,declare and define the function called in unity and do your required in that specific function

i would prefer the 2 ways as i have done enough work on objective c before coming to unity so it helps me there,and i am kinda of confused what you are actually trying to do can you just be a little more precise of what you actually want to create maybe i can suggest you a more easy way out …

okay so now suppose you want to get the device locale in unity so what you can do here is

write this code in the native function ou created in xcode(awesome function in the code provided above)

int AwesomeFunction(int awesomeParameter)
{
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
}

This will return a two letter code for the currently selected language. “en” for English, “es” for Spanish, “de” for German, etc. For more examples, please see this Wikipedia entry (in particular, the 639-1 column):

so now you have the locale in the variable which you can return to unity and do whatever changes you want to do based on the locale,
you can either return it as a return type or set it in player prefs and read it in unity.

correct me if i took your question wrong.

I have developed game application in unity and give login facility from facebook. i used the AppController.mm to login from facebbok and its working fine but i need if user login from facebook and return to the game then game will start automatically, so needed one function to call from AppController to unity for test user is looged or not. it is possible, anyone can help?

Thanks