/// <summary>
        ///   Gets the version of the native application.
        /// </summary>
        /// <param name = "applicationPath">The application path with or without the ".app" extension.</param>
        /// <returns></returns>
        public static Version GetVersion(String applicationPath)
        {
            String path = applicationPath;

            if (Path.GetExtension(applicationPath) != ".app")
            {
                path += ".app";
            }
            path = Path.Combine(path, "Contents");
            path = Path.Combine(path, "Info.plist");

            // Create an pool
            ObjCClass nsautoreleasepoolClass = ObjCClass.Get("NSAutoreleasePool");
            ObjCClass nsstringClass          = ObjCClass.Get("NSString");
            ObjCClass nsdictionaryClass      = ObjCClass.Get("NSDictionary");

            ObjCId pool = nsautoreleasepoolClass.Alloc();

            pool = pool.Init();

            // Read the Info.plist file
            ObjCId nsstringPath     = new ObjCId(nsstringClass.SendMessage("stringWithUTF8String:", path));
            ObjCId nsstringKey      = new ObjCId(nsstringClass.SendMessage("stringWithUTF8String:", "CFBundleShortVersionString"));
            ObjCId nsdictionaryDict = new ObjCId(nsdictionaryClass.SendMessage("dictionaryWithContentsOfFile:", nsstringPath.Pointer));
            ObjCId nsstringVersion  = new ObjCId(nsdictionaryDict.SendMessage("valueForKey:", nsstringKey.Pointer));

            // Return the string version
            IntPtr result  = nsstringVersion.SendMessage("UTF8String");
            String version = Marshal.PtrToStringAuto(result);

            // Release the pool
            pool.Release();

            return(new Version(version));
        }
Example #2
0
 public Object()
 {
     native_class = ToObjCClass ();
     NativeObject = (IntPtr) ObjCMessaging.objc_msgSend (native_class.ToIntPtr (), "alloc", typeof (IntPtr));
 }
Example #3
0
        private ObjCClass ToObjCClass()
        {
            if (native_class != null)
                return native_class;

            native_class = ObjCClass.FromObject (this);

            return native_class;
        }