I've got this source (xcode 3.2.5):
NSLog(#"IPHONE = %d, SIMULATOR = %d, MAC = %d", TARGET_OS_IPHONE, TARGET_IPHONE_SIMULATOR, TARGET_OS_MAC);
And I get this result:
2012-03-30 13:50:06.777 MyApp[36810:207] IPHONE = 1, SIMULATOR = 1, MAC = 1
No wonder my #if statements are confused!
What gives? Any ideas?
FWIW: On (tethered) iPod Touch I get this: IPHONE = 1, SIMULATOR = 0, MAC = 1
Added: Well, I figured out that my original problem with #if was due to misspelling TARGET_OS_IPHONE as TARGET_OS_PHONE in several places. (Good ol' copy/paste!)
Would still like to find a definitive description of how Apple's defines are supposed to be set.
Use TARGET_OS_IPHONE (only!) for differentiating between iOS and OSX.
#if TARGET_OS_IPHONE
// iOS
#else
// Mac OS X
#endif
TARGET_OS_MAC will be 1 on both OSX and iOS; it predates iOS, and iOS is considered a variant of OSX as far as TargetConditionals.h is concerned.
I might be wrong here, but my assumption was that TARGET_OS_MAC specifies that you are building for Mac OS X (as opposed to, say, win32). iOS is actually a version of Mac OS X (although it is not branded / marketed as such).
To see how they are all defined, choose a build target and command-click their definition in xcode.
In the header file, the macros are defined as such:
TARGET_OS_MAC - Generate code will run under Mac OS
TARGET_OS_WIN32 - Generate code will run under 32-bit Windows
TARGET_OS_UNIX - Generate code will run under some non Mac OS X unix
TARGET_OS_EMBEDDED - Generate code will run under an embedded OS variant
of TARGET_OS_MAC
TARGET_OS_IPHONE - Generate code will run under iPhone OS which
is a variant of TARGET_OS_MAC.
So, it can be expected that TARGET_OS_MAC is defined for iOS, as well as TARGET_OS_IPHONE for example.
Related
I am trying to use some old IOKit functionality in a new Swift 4.0 Mac app (not iOS). I have created a bridging header to use an existing Objective C third party framework, DDHidLib, and I am current working in Xcode 9.
The code that attempts to create a plug in interface for a usb gamepad falls over on IOCreatePlugInInterfaceForService, returning a non-zero error.
The truly bizarre thing is I have an older app created in a previous version of Xcode that uses the same framework and works correctly after opening in the new Xcode 9. This previous project is still Swift using a bridging header for the same Obj-C framework. I have checked the build settings and tried to make everything match, but I get the same result; the old app works but any new apps do not.
Is there a way to either: find out the exact differences in build settings/compilers to see what the elusive difference may be, OR to step into the IOCreatePlugInInterfaceForService IOKit method to see what may be causing the error to be returned in one project but not another?
EDIT: Here is the method that is failing:
- (BOOL) createDeviceInterfaceWithError: (NSError **) error_; {
io_name_t className;
IOCFPlugInInterface ** plugInInterface = NULL;
SInt32 score = 0;
NSError * error = nil;
BOOL result = NO;
mDeviceInterface = NULL;
NSXReturnError(IOObjectGetClass(mHidDevice, className));
if (error)
goto done;
NSXReturnError(IOCreatePlugInInterfaceForService(mHidDevice, kIOHIDDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&plugInInterface,&score));
if (error)
goto done;
//Call a method of the intermediate plug-in to create the device interface
NSXReturnError((*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &mDeviceInterface));
if (error)
goto done;
result = YES;
done:
if (plugInInterface != NULL)
{
(*plugInInterface)->Release(plugInInterface);
}
if (error_)
*error_ = error;
return result;
}
In the old version that works, IOCreatePlugInInterfaceForService always returns a value of 0. In all the versions that don't work, the return value appears to always be -536870210. The mHidDevice in this function is the io_object_t handle for the device.
EDIT2: Here is the IORegistryExplorer page for the device
Finally managed to resolve this after weeks of head scratching. The new Xcode 9 uses app sandboxing to basically prevent access to USB, bluetooth, camera and microphone etc. by default in a new app. Once I switched this off it reverted to it's expected behaviour.
Glad it was such a simple answer in the end but disappointed Xcode does not provide more descriptive error messages or responses to let a user know they are essentially preventing themselves from accessing the parts of the system they need.
Looks like kIOReturnNoResources is returned if the loop at the end of IOCreatePlugInInterfaceForService completes with haveOne == false for whatever reason. Perhaps Start() is returning false because another process or driver already has exclusive access? I'd check what clients the device has in IORegistryExplorer.
This error also happens when an application is trying to access the camera or bluetooth on MacOS 10.14 and higher. Permission shall be granted either explicitly by user (pop-up window), or through the Security & Privacy. The application should check for permission as shown here.
I have downloaded the latest source from OpenSSL Page (released on April 7th, 2014), and created a libcrypto.a library using Tutorial Where i have followed the steps in which i run ./build-openssl.sh script file to generate libcrypto.a file for all environments (armv7s, armv7, i386) on Mac OS X having version 10.9.2.
I am able to encrypt / decrypt the date using EVP_aes_256_cbc encryption but my code gets failed when i try to get RAND_byte. The code gets crashed on RAND_byte call.
Below are the codes, which i am trying to get the RAND_byte seeds:
// Code 1
unsigned char seed[32];
RAND_bytes(seed, 32);
// Code 2
int count = 24;
unsigned char *buffer = (unsigned char *)calloc(count, sizeof(unsigned char));
RAND_bytes(buffer, count);
// Code 3
int count = 24;
unsigned char *buffer = (unsigned char *)malloc(sizeof(int)*count);
RAND_bytes(buffer, count);
// Code 4
int count = 24;
unsigned char *buffer = OPENSSL_malloc(count);
RAND_bytes(buffer, count);
When I run above code on iOS 6.0/6.1 Simulator, It gets crashed on RAND_byte call and I get “_interposition_vtable_unimplemented” on Thread 1 and no message get displayed on console.
When I run the same code on iOS 7.0+ Simulator, It gets crashed on RAND_byte call and I get “__pthread_kill” on Thread 1 and “Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003 called from function RAND_poll in image CryptographyTest.” on Console.
But WHEN I run the same code on iPad with iOS 7.0.4, All above codes runs perfectly. Where i get the return value from RAND_byte is 1.
I don’t understand the behavior that some of the functions does not work on iOS simulator but everything works with iOS devices.
Any help highly appreciated! Many thanks in advance.
... using Tutorial where i have followed the steps in which i
run ./build-openssl.sh script file to generate libcrypto.a file
for all environments (armv7s, armv7, i386)
...
I don’t understand the behavior that some of the functions does
not work on iOS simulator but everything works with iOS devices.
The script is wrong for your usage:
Its not building for the simulator. Its building for the desktop. This:
ARCHS=("armv7s" "armv7" "i386")
SDKS=("iphoneos" "iphoneos" "macosx")
Probably needs to be changed to:
ARCHS=("armv7s" "armv7" "i386")
SDKS=("iphoneos" "iphoneos" "iPhoneSimulator")
With iPhoneSimulator, the proper SDK will be used:
$ ls /Applications/Xcode.app/Contents/Developer/Platforms/
MacOSX.platform iPhoneSimulator.platform
iPhoneOS.platform
Does the project you are using claim its multi-arch and for the iPhone and iPhone Simulator? Or does it claim its multi-arch and for iPhone and OS X?
and created a libcrypto.a library for iOS use using Tutorial.
I don't know about that Tutorial, but OpenSSL has procedures to build the library for iOS. You can find it in the FIPS User Guide 2.0, Appendix E.
You can fetch a prebuilt version of OpenSSL for iOS at Github. It was built using the OpenSSL procedures. Its a fat library, and it has i386, ARMv7, ARMv7s and ARM64 architectures.
“__pthread_kill” on Thread 1 and “Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003 called from function RAND_poll in image CryptographyTest.” on Console.
I believe this indicates the OpenSSL library was not built properly for the simulator or devices.
int count = 24;
unsigned char *buffer = OPENSSL_malloc(count);
RAND_bytes(buffer, count);
Just bike shedding here, but you ignored the return value from RAND_bytes. According to the docs on RAND_bytes:
RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
obtained by ERR_get_error(3).
Silent failures are a kiss of death to high integrity software.
I am changing the name of my app based on the device it is running on through configuration files, i.e. I put in an _iPhone, _iPad or _Universal in the display name accordingly.
To do this I am using xcconfig files as follows:
TARGETED_DEVICE_FAMILY = 1,2
APP_NAME1 = Something_iPhone
APP_NAME2 = Something_iPad
APP_NAME1,2 = Something_Universal //1,2 The "," causes a problem here.
The problem is that the comma character is causing a problem:
*Build setting 'APP_NAME1,2' does not have a valid base name.*
Any ideas?
No apps will be approved for app store with using the trade marked names such as iPhone or iPad try using something else. I have had that even in the binary and not in the display and they rejected it in review. If you want to create a set of codes for universal porpose the take a look at this code snippet. I use this a lot in my universal apps.
`if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
NSLog(#"iPad Idiom");
else
#else
NSLog(#"iPhone Idiom");
#endif
Adrian
I am compiling a small application with hardly 10 lines of code in Xcode 4. While compiling it seems to be hanging. But when i compile a small Hello World application, it seems to work fine. Earlier today it was working fine with a larger application. Could someone please tell me whats happening? and how can i overcome this issue and allow it to compile faster like before??
BR,
Suppi
Edited:
Ok, Xcode version 4.0.2, Ram size is 2GB, MAC OS X version 10.6.8.
and my code for the program i am running:
I am basically checking to see how the interface between an Objective C and C works:
In my C file:
void helloWorld()
{
printf("hellow Woeld c");
hellowworldToObjC();
}
void hellowworldToObjC()
{
HelloWorldC();
}
and Objective C class:
id refToSelf;
- (id)init {
self = [super init];
if (self) {
refToSelf = self; // Saving self in pointer
}
return self;
}
-(void)HelloWorldObjc
{
NSLog(#"Hello World from Objc C");
[self HellowTestingC];
}
-(void)HellowTestingC
{
helloWorld();
}
#end
void HelloWorldC()
{
[refToSelf HelloWorldObjc];
}
Sample Xcode when it is "hanging" (and by "hanging", do you mean truly hanging or does it eventually work).
You also might want to leave top -u running in a terminal window and see how many pagein/pageout events occur when the "hang" happens. If you are paging, it'll feel like a hang.
0 pageouts meanings you aren't swapping (the pageins are just the source files that are #included being read).
Post the sample.
It was crazy with Xcode 4, the CPU was 190%, and Xcode 4 was not responding, so i went ahead and installed Xcode 3.2.6. Now all working fine :).
I'm having trouble compiling the current release.
I was able to download a copy of the source distribution today using:
hg clone https://core-plot.googlecode.com/hg/ core-plot
I opened the "core-plot/framework".
I then double clicked on CorePlot-CocoaTouch.xcodeproj to launch Xcode.
When I build the project I get the following error:
-(void)bind:(NSString *)binding toObject:(id)observable withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
{
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
[NSException raise:CPException format:BindingsNotSupportedString];
Format not a string literal and no formal arguments
#else
[super bind:binding toObject:observable withKeyPath:keyPath options:options];
#endif
}
I am running on a new MacBook with OS 10.6, and IPhone Simulator 4.0.
Any help will be greatly appreciated.
Charles
A more appropriate place to ask this question would be the Core Plot mailing list, because I'm one of the few developers for the project that regularly visits here.
That said, the issue here is that we're using a string constant for a format string, which Xcode now seems to be warning about (rightly so, as this can lead to problems). To work around this for now, you can replace the line in CPLayer.m
static NSString * const BindingsNotSupportedString = #"Bindings are not supported on the iPhone in Core Plot";
with
#define BindingsNotSupportedString #"Bindings are not supported on the iPhone in Core Plot"
Search in your project for BindingsNotSupportedString, seems like it's not in the current file and therefore needs to be included. Or just try to change this to an acceptable format.