| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Oct 27, 2008
Posts: 13
![]() |
Hi All
I have a snippet of code which works in 10.4 but it supported in 10.3. Hence i want some APIs to determine the OS , so that the snippet gets executed in the proper OS. Also, please let me know if u have any better way to distinguish between the versions programmatically. ******Rouble****** |
| QUOTE Thanks | |
![]() Member Since: Oct 27, 2008
Posts: 13
![]() |
I have got this from help :-
NSString *str = [[NSProcessInfo processInfo] operatingSystemVersionString]; But i am not able to use it properly. ******Rouble****** |
| QUOTE Thanks | |
![]() Member Since: Mar 15, 2007
Posts: 161
![]() Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM
|
Quote:
There are a few ways to approach this; which one is best depends upon the specifics of your needs. Since you haven't provided any details about why you are trying to do this in C++, I'll take a wild guess that yours is a cross-platform app that doesn't depend upon a GUI front end but which does need OS version information for some reason. You can access Cocoa framework classes from an Objective-C++ file (i.e., a C++ file with the extension ".mm"). Assuming that redefining the top level of your C++ application as an Objective-C++ file is not an option (which it wouldn't be for a cross-platform app), one approach would be to create a separate Objective-C++ file to do the work, as in the following (very rough) example code: Code:
main.cpp:
#include "MyCocoaBridge.h";
int main (int argc, char * const argv[])
{
getVersion();
return 0;
}
---------------------------------
MyCocoaBridge.h:
void getVersion(void);
---------------------------------
MyCocoaBridge.mm:
#import <Foundation/Foundation.h>
#include <iostream>
void getVersion(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
std::cout << [version UTF8String] << "\n";
[pool drain];
return;
}
I hope this helps to put you on a workable track. |
|
| QUOTE Thanks | ||
![]() Member Since: Oct 27, 2008
Posts: 13
![]() |
I am using a empty project and included al the frameworks manually. ---------------------------------------------------------------------- main.cpp: #include "MyCocoaBridge.h"; int main (int argc, char * const argv[]) { // codes using disk arbitrartion framework(disk locking -unlocking) getVersion(); return 0; } --------------------------------- MyCocoaBridge.h: void getVersion(void); --------------------------------- MyCocoaBridge.mm: #import <Foundation/Foundation.h> #include <iostream> void getVersion(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString]; std::cout << [version UTF8String] << "\n"; [pool drain]; return; } ---------------------------------------------------------------- I have included the foundation framework but it is not able to identify it..... It is showing the following errors : /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:60: error: expected unqualified-id before '@' token /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:62: error: expected constructor, destructor, or type conversion before '*' token /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:63: error: 'NSString' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:63: error: 'aSelectorName' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:64: error: 'NSString' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:64: error: 'aClassName' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:65: error: expected constructor, destructor, or type conversion before '*' token /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:68: error: variable or field 'NSLog' declared void /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:68: error: 'NSString' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:68: error: 'format' was not declared in this scope /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:68: error: expected primary-expression before '...' token /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:68: error: initializer expression list treated as compound expression /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:69: error: variable or field 'NSLogv' declared void and many more errors of this sort. I fail to understand why it is not able to identify Founadation framework whereas it is happy to be with disk arbitrartion framework. ******Rouble****** |
| QUOTE Thanks | |
![]() Member Since: Oct 27, 2008
Posts: 13
![]() |
Hi
I have done some modifications in the settings and it is working wonders. But tell me one thing....how should i return the value of the string in the cpp file.I mean what variable should i use to store the value returned by the function. ******Rouble****** |
| QUOTE Thanks | |
![]() Member Since: Mar 15, 2007
Posts: 161
![]() Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM
|
I'm glad you figured out the project settings. I'm running Xcode on 10.5, and perhaps should have asked you which version of Xcode you are running since you are on 10.4 - that might be why you had some additional headaches with the project settings.
NSString has a variety of functions for creating a C-style array of characters. Those should be easy enough to return and use in your C++ code. |
| QUOTE Thanks | |
![]() Member Since: Oct 27, 2008
Posts: 13
![]() |
But can please u tell me how to do the following :
I want to compare the value returned by ( NSString *str = [[NSProcessInfo processInfo] operatingSystemVersionString] ) with 10.4 .If it is less than that execute one piece of code otherwise if it is greater then execute other piece of code. ******Rouble****** |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Running Windows on a Mac: A Switcher's Guide | cwa107 | Running Windows (or anything else) on your Mac | 276 | 04-20-2013 11:28 PM |
| Running Windows on Mac | rickmahmoud | Running Windows (or anything else) on your Mac | 7 | 02-16-2008 11:31 PM |
| Mac Pro keeps crashing when using with KVM. where to start my investigation? | AlexUK | Apple Desktops | 6 | 06-20-2007 05:50 AM |
| Mac Users Get More ISP Choices | schweb | Apple Rumors and Reports | 1 | 03-06-2003 10:57 AM |
All times are GMT -4. The time now is 06:20 PM.
Powered by vBulletin