I need a small script to write a file with in a ‘.m’ Object-C class.
Basically I want to write and save a txt doc (or even to a local MySQL db) using Obj-C. If anyone has such code then this would be great.
The following code is used to addDevicetoList for the bluetooth class:
-(void)addDeviceToList:(IOBluetoothDevice*)inDevice
{
id newButton;
const BluetoothDeviceAddress* addressPtr = [inDevice getAddress];
id buttonIcon = NULL;
BluetoothDeviceClassMajor deviceClassMajor = [inDevice getDeviceClassMajor];
BluetoothDeviceClassMinor deviceClassMinor = [inDevice getDeviceClassMinor];
NSString* deviceCODString = nil;
NSString* deviceAddressString = nil;
NSString* deviceNameString = [inDevice getName];
NSString* connectionInfo = nil;
// Get the device address and deal with the name.
if( addressPtr )
{
deviceAddressString = [NSString stringWithFormat:@"%02x-%02x-%02x-%02x-%02x-%02x", addressPtr->data[0],
addressPtr->data[1],
addressPtr->data[2],
addressPtr->data[3],
addressPtr->data[4],
addressPtr->data[5]];
}
if( !deviceNameString )
{
deviceNameString = @"<Name not yet known>";
}
// Make sure we don't already have this device in the list.
if( ![self saveNewDeviceIfAcceptable] )
{
// Already have seen it. Bail.
return;
}
// Create COD info string.
deviceCODString = [NSString stringWithFormat:@"Major Class: %@ (0x%02x)\nMinor Class: %@ (0x%02x)",
GetStringForMajorCOD( [inDevice getDeviceClassMajor] ),
[inDevice getDeviceClassMajor],
GetStringForMinorCOD( [inDevice getDeviceClassMajor], [inDevice getDeviceClassMinor] ),
[inDevice getDeviceClassMinor]];
// If there is a connection in place shows the connection handle:
if ( [inDevice isConnected] )
{
connectionInfo = [NSString stringWithFormat:@"Connected, Connection Handle 0x%04x", [inDevice getConnectionHandle]];
}
else
{
connectionInfo = [NSString stringWithFormat:@"Not Connected"];
}
// load up an image for the class of device which we have found.
[self getIconForClassOfDevice:&buttonIcon
majorClass:deviceClassMajor
minorClass:deviceClassMinor];
[buttonIcon setScalesWhenResized:TRUE];
[buttonIcon setSize:gCellImageSize];
// Make space for and get a button for the new device.
[_buttonMatrix addRow];
newButton = [_buttonMatrix cellAtRow:[_buttonMatrix numberOfRows]-1 column:0];
if( !newButton ) return;
// Set the button's attributes.
[newButton setImage:buttonIcon];
[newButton setTitle:[NSString stringWithFormat:@"%@ / %@\n%@\n%@", [deviceAddressString uppercaseString], deviceNameString, deviceCODString, connectionInfo]];
[newButton setTag:(int)inDevice];
// make it the right type of button and update the display.
[_buttonMatrix sizeToCells];
[_matrixView setNeedsDisplay:TRUE];
}
The write to .txt doc will need to go in here somewhere probably at the end, so if you do now a way to do it then please let me know.
Many Thanks si:)
Model: iBookG4 and a G5
AppleScript: Xcode 2.4.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)