Compile error in CorePlot-CocaTouch project - iphone

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.

Related

IOCreatePlugInInterfaceForService returns mysterious error

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.

OpenSSL RAND_byte issue with iOS Simulator

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.

including Kal.a (from Kal calendar) and including libidn.a (xmpp framework) causes app to crash

After trying really hard i am posting this qustion in the 2 o clock of night in my office.
The problem is :
1) i have included Kal calender (link here) in my application
2) And its really working fine before i decided to include xmpp framework(xmpp framework) in my application.
3) The Main problem is when i try to include libidn.a file and then compile the project it gives me 4 errors , and to remove these error i have to remove "Other linker flag -> -all_load".
4) Here the problem begins when i have removed -all_laod flag and compile , app compiles success fully. But i try to run my app and press calendar button to load calender it crashes with following error:
-[__NSDate cc_dateByMovingToFirstDayOfTheMonth]: unrecognized selector sent to instance 0x75b85c0 2012-06-12 01:38:47.483 BizPro[10251:11903]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDate
cc_dateByMovingToFirstDayOfTheMonth]: unrecognized selector sent to
instance 0x75b85c0'
* First throw call stack: (0x209e022 0x22f0cd6 0x209fcbd 0x2004ed0 0x2004cb2 0x12bc3d 0x12bb91 0x13149e 0x1315f6 0x12961 0xa8d38f
0xa8d5eb 0xa9dff1 0xa9e85f 0xa9e9e1 0xbbc5c2 0xa02d21 0x209fe42
0x856679 0x860579 0x7e54f7 0x7e73f6 0x874160 0x9d4f30 0x207299e
0x2009640 0x1fd54c6 0x1fd4d84 0x1fd4c9b 0x26e67d8 0x26e688a 0x9c4626
0x2a9d 0x2a15 0x1) terminate called throwing an exception(lldb)
4) I know very well that this error is a misguide (NSDate is not causing the crash but the collision of static libraries is doing it , i think so) , because when i again add -all_load flag and remove the libidn.a file from my project , It compile and RUN successfully and calendar displays my data smoothly.
i googled a lot about it .. and got very little guidance .. relating the solution to workspaces and all that .. But i really dont know what could be the solution .. Plz help me
Thanks
cc_dateByMovingToFirstDayOfTheMonth
is an addition to NSDate that is defined in NSDateAdditions.h from the Kal Framework.
I had no end of problems and wanted more customisation of the Kal framework so I just dragged all the source code into my project.
If you still have issues with the framework then remove Kal.a and just bring in the source code :) then you can get dirty with it
If you rather keep Kal as a subproject, the way to fix this is to link the addition files.
Under
Project -> Build Settings -> Linking -> Other Linker Flags
add '-all_load'
sorry i am answering late ..
i solved the problem ..
removed kal.a file and just included src folder (all the header files required)
so that i will not collide with the other static library ...
Similar problem here. Because I'm using Parse Framework, can't add -all_load, so integrating static library will never work for me. The simplest way is to add all source files in src folder to my own project, rather than adding Kal.xcodeproj. Other steps to config "copy bundle files" or "header search path" etc are still necessary. I also need to add these lines from Kal_Prefix.pch to my own project.pch.
#import "NSDate+Convenience.h"
#define RGBCOLOR(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1]
#define RGBACOLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
#define kDarkGrayColor RGBCOLOR(51, 51, 51)
#define kGrayColor RGBCOLOR(153, 153, 153)
#define kLightGrayColor RGBCOLOR(185, 185, 185)

Sudzc with iOS 5 and ARC

I've been trying to get a webservices working using Sudzc. Whenever I convert my WSDL to obj-c without automatic reference counting it works just fine. The problem is, we are building all our applications in iOS 5 now and all our code uses ARC. Sudzc now also allows you to create a bundle with ARC enabled but when I run this code it always returns null.
I tried debugging the Sudzc code and it does receive a correct xml response back from the service. Somewhere something is lost in translation. I tried converting the working Sudzc code without ARC into code with ARC enabled but as soon as I've fixed all errors it returns null again.
Did anyone encounter this and know what is going wrong? Would save me loads of time not having to debug the whole Sudzc code by myself.
In my case (SUDZC with ARC for IOS), I have replaced the folowing code in SoapRequest.m file;
CXMLNode* element = [[Soap getNode: [doc rootElement] withName:#"Body"] childAtIndex:0];
with
CXMLNode* element = [[Soap getNode: [doc rootElement] withName:#"soap:Body"] childAtIndex:0];
Somehow the respective function is searching for the root element with name "Body". After inspecting the soap envelope it is easy to see the root element's name is "soap:Body".
My webService was create in Java with Axis Eclipse.
FOR ARC I use : "soapenv:Body"
And in the file SoapObject.m I add
#import "Soap.h"
#import "SoapObject.h"
In my case "env:Body" worked. Check your return xml (by printing) and replace appropriately
In my case it was an .Net web service (WCF) and I had to use s:Body:
Found out by printing the CXML document:
CXMLNode* test = [doc rootElement];
NSLog(#"%#",test);
Here I got this:
<CXMLElement 0x68c1a50 [0x68c1b10] s:Envelope <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><**s:Body**><GetUserIDResponse xmlns="http://tempuri.org/"><GetUserIDResult>8</GetUserIDResult></GetUserIDResponse></s:Body></s:Envelope>>
Thanks to previous posts I was able to find it out and posted the complete answer again on my blog: http://www.dailycode.info/Blog/post/2012/08/07/SUDZC-webservices-always-return-0-(WCF-web-service-and-IOS-client).aspx

How do I extract pixel data from DICOM files on iOS?

Does anyone know how I can extract the pixel data from a DICOM file and pass it to an image viewer on iOS?
Sorry if this is a simple question, but it seems to be a major component to a huge can of worms I have opened.
I'm using GDCM on iOS. I haven't pushed it very hard yet but it's working well so far. I basically followed the directions for hacking XCode projects to run in iOS in this excellent article on ITK.
Here's how I got it to compile for iOS:
Downloaded source from sourceforge, installed cmake via ports. You'll need a recent version of cmake (I'm using 2.8.2)
If the source is in a folder called gdcm-2.0.17/, then create another directory at that level (say gdcmbin), cd to that directory, and enter ccmake -GXCode ../gdcm-2.0.17/ in the terminal window. This creates the XCode project. When I did this I didn't create any of the example programs or create shared libraries (which won't work in iOS). Just run the defaults.
Follow the directions in the ITK paper on changing the build options (step #7 on page 4).
Then link GDCM into your project using the excellent instructions at Clint Harris' blog
When you're setting up the header search path in your project to GDCM - you have to enter two paths: blah/gdcm-2.0.17/Source/** and blah/gdcmbin/**. The trailing '/Source' on the first path is necessary - otherwise you get headers that aren't appropriate for your architecture.
One glitch (annoying but haven't spent the time to figure it out yet): you get a bunch of linking errors when you switch from simulator to device (or vice versa). This is because the gdcm project doesn't put the outputs into different directories for different targets. So - run a clean and rebuild in the gdcm project when you're switching. I'll probably get annoyed by this soon enough to change it :-).
Here's a rough snippet of how you'd call the library and put the results in an Objective-C dictionary:
NSMutableDictionary * imageDictionary = [[NSMutableDictionary alloc] initWithCapacity:40];
// The output of gdcm::Reader is a gdcm::File
gdcm::File &file = reader.GetFile();
// the dataset is the the set of element we are interested in:
gdcm::DataSet &ds = file.GetDataSet();
const Tag studyInstance(0x0020,0x000d); // Study Instance UID
const DataElement &dicomVal = ds.GetDataElement(studyInstance);
std::string stringVal( dicomVal.GetByteValue()->GetPointer(), dicomVal.GetByteValue()->GetLength() );
NSString *val = [NSString stringWithCString:stringVal.c_str() encoding:[NSString defaultCStringEncoding]];
[imageDictionary setObject:val forKey:#"studyInstanceUID"];
(Note: this is in an *.mm file that mixes C++ and ObjectiveC)
Imebra has an Objective-C wrapper that can be used also with Swift.
#import "imebraobjc/imebra.h"
// Get the DICOM dataset from file
NSError* error = nil;
ImebraDataSet* pDataSet = [ImebraCodecFactory loadFromFile:#"test.dcm" error:&error]
// CHeck the patient name (automatically convert from DICOM charsets to UTF-8)
NSString* checkPatientName = [pDataSet getString:[[ImebraTagId alloc] initWithGroup:0x10 tag:0x10] elementNumber:0 error:&error]; // Automatically converted to UTF-8 if necessary
// Get the frame 0
ImebraImage* pCheckImage = [pDataSet getImageApplyModalityTransform:0 error:&error];
// Get the image data
ImebraReadingDataHandlerNumeric* readingDataHandler = [pCheckImage getReadingDataHandler:&error];
// Scan the pixels. Access the data handler memory for faster data access
for(unsigned int pixel(0); pixel != readingDataHandler.size; ++pixel)
{
unsigned int pixelValue = [readingDataHandler getUnsignedLong:pixel error:&error];
}
ImebraDrawBitmap* pDrawBitmap = [[ImebraDrawBitmap alloc] init];
// Obtain a NSImage (UIImage on iOS)
NSImage* pNsImage = [pDrawBitmap getImebraImage:pCheckImage error:&pError];
If you want to find DICOM software, look at idoimaging.com, a clearinghouse for medical imaging software. You can choose your platform, input format, output format, language, etc. iOS isn't listed as a format, but much of the software listed there is available with source, useful in library form, and available for MacOS X. For example, I selected:
input format: DICOM
platform: Macintosh
language: C
and found several packages. Given the similarities between MacOS and iOS and the fact that some of these are cross-platform with source included, it shouldn't be too difficult to get one of them working on iOS.