591Fonts on the iPhone

I never seen to be able to remember the fonts available on the iPhone. Here’s the code to print out all font families and font styles.
for (NSString *familyName in [UIFont familyNames]) {
	NSLog(@"%@, %@", familyName, [UIFont fontNamesForFamilyName:familyName]);
}
And here is the current result:
2010-05-17 17:38:05.931 fonts[20843:207] AppleGothic, (
    AppleGothic
)
2010-05-17 17:38:05.932 fonts[20843:207] Hiragino Kaku Gothic ProN, (
    "HiraKakuProN-W6",
    "HiraKakuProN-W3"
)
2010-05-17 17:38:05.932 fonts[20843:207] Arial Unicode MS, (
    ArialUnicodeMS
)
2010-05-17 17:38:05.932 fonts[20843:207] Heiti K, (
    "STHeitiK-Medium",
    "STHeitiK-Light"
)
2010-05-17 17:38:05.932 fonts[20843:207] DB LCD Temp, (
    DBLCDTempBlack
)
2010-05-17 17:38:05.932 fonts[20843:207] Helvetica, (
    "Helvetica-Oblique",
    "Helvetica-BoldOblique",
    Helvetica,
    "Helvetica-Bold"
)
2010-05-17 17:38:05.932 fonts[20843:207] Marker Felt, (
    "MarkerFelt-Thin"
)
2010-05-17 17:38:05.933 fonts[20843:207] Times New Roman, (
    TimesNewRomanPSMT,
    "TimesNewRomanPS-BoldMT",
    "TimesNewRomanPS-BoldItalicMT",
    "TimesNewRomanPS-ItalicMT"
)
2010-05-17 17:38:05.933 fonts[20843:207] Verdana, (
    "Verdana-Bold",
    "Verdana-BoldItalic",
    Verdana,
    "Verdana-Italic"
)
2010-05-17 17:38:05.933 fonts[20843:207] Georgia, (
    "Georgia-Bold",
    Georgia,
    "Georgia-BoldItalic",
    "Georgia-Italic"
)
2010-05-17 17:38:05.933 fonts[20843:207] Arial Rounded MT Bold, (
    ArialRoundedMTBold
)
2010-05-17 17:38:05.933 fonts[20843:207] Trebuchet MS, (
    "TrebuchetMS-Italic",
    TrebuchetMS,
    "Trebuchet-BoldItalic",
    "TrebuchetMS-Bold"
)
2010-05-17 17:38:05.933 fonts[20843:207] Heiti TC, (
    "STHeitiTC-Light",
    "STHeitiTC-Medium"
)
2010-05-17 17:38:05.933 fonts[20843:207] Geeza Pro, (
    "GeezaPro-Bold",
    GeezaPro
)
2010-05-17 17:38:05.934 fonts[20843:207] Courier, (
    Courier,
    "Courier-BoldOblique",
    "Courier-Oblique",
    "Courier-Bold"
)
2010-05-17 17:38:05.934 fonts[20843:207] Arial, (
    ArialMT,
    "Arial-BoldMT",
    "Arial-BoldItalicMT",
    "Arial-ItalicMT"
)
2010-05-17 17:38:05.934 fonts[20843:207] Heiti J, (
    "STHeitiJ-Medium",
    "STHeitiJ-Light"
)
2010-05-17 17:38:05.934 fonts[20843:207] Arial Hebrew, (
    ArialHebrew,
    "ArialHebrew-Bold"
)
2010-05-17 17:38:05.934 fonts[20843:207] Courier New, (
    "CourierNewPS-BoldMT",
    "CourierNewPS-ItalicMT",
    "CourierNewPS-BoldItalicMT",
    CourierNewPSMT
)
2010-05-17 17:38:05.934 fonts[20843:207] Zapfino, (
    Zapfino
)
2010-05-17 17:38:05.934 fonts[20843:207] American Typewriter, (
    AmericanTypewriter,
    "AmericanTypewriter-Bold"
)
2010-05-17 17:38:05.935 fonts[20843:207] Heiti SC, (
    "STHeitiSC-Medium",
    "STHeitiSC-Light"
)
2010-05-17 17:38:05.935 fonts[20843:207] Helvetica Neue, (
    HelveticaNeue,
    "HelveticaNeue-Bold"
)
2010-05-17 17:38:05.935 fonts[20843:207] Thonburi, (
    "Thonburi-Bold",
    Thonburi
)

519A bit about Frameworks and Static Libraries on the iPhone

Frameworks are a way to share code and other resources between application. As sharing code between applications is not really possible on the iPhone (as is dynamic loading of libraries) it does not really make much sense to use Frameworks on the iPhone – except maybe for the nice handling of reusable code. Where with Frameworks the specific files are accessable after the Framework is added to a project, working with Static Libraries is a bit more of an hussle. You not only need to add the library, but also need to make sure to set the right Header Search Paths, which can become troublesome when working with SVN’ed projects. And because the architecture differs on the iPhone (ARM) and the Simulator (i386), having precompiled libraries is not the best solution. But adding a depended library project to your projects kind of negates the advantages of having reusable code by adding unnecessary complications. Recommendation? Just add the desired files to your project. And if you really mind, don’t copy, but only include by reference.

492Target Conditionals

TargetConditionals.h
#include ;

// Gives you TARGET_IPHONE_SIMULATOR and TARGET_OS_IPHONE target conditionals.
// Set hello to "Hello, "!
#if TARGET_IPHONE_SIMULATOR
   NSString *hello = @"Hello, iPhone Simulator!";
#else
   NSString *hello = @"Hello, iPhone device!";
#endif

//Determining whether you’re compiling for the iPhone OS
#if TARGET_OS_IPHONE
   #import 
#else
   #import 
#endif
Conditionalizing Compilation and Linking from the Apple Dev Library. I came across a simple and short IPHONE target conditional at some framework, but that did not seemed to do the trick. I am probably missing something there. – Update 1. tconf might be a step into the right directions. Just out of curiosity, here a incomplete list of available target conditionals:
TARGET_IPHONE_SIMULATOR
TARGET_CARBON
TARGET_OS_IPHONE
TARGET_CPU_PPC 
TARGET_CPU_PPC64
TARGET_CPU_68K
TARGET_API_MAC_OSX
PRAGMA_ALIGN_SUPPORTED
TARGET_OS_UNIX
TARGET_OS_EMBEDDED
TARGET_OS_MAC
TARGET_OS_WIN32
TARGET_OS_UNIX
TARGET_OS_EMBEDDED
TARGET_RT_MAC_CFM
TARGET_RT_MAC_MACHO
...
Update 2. And that’s the motherload. Nice of Apple to open-source that.

490‘Initial interface orientation’ setting in Info.plisy

The Informatin Property List of iPhone Applications has the optional setting of Initial interface orientation. Is a NSString type, I was wondering, which values were supported, bzw required. Luckily, auto-complete is your friend. For completeness’ sake, here are the accepted values: Portrait (top home button) Portrait (bottom home button) Landscape (left home button) Landscape (right home button)

389Realtime Video on the iPhone from a Local Server

Following Problem: How do stream video from a local machine to an iPhone OS device in real time? Real-time is an absolutely necessary. That basically rules out the HTTP Streaming Server (as described previously), as it’s capable of streaming to multiple clients, but has to sacrifice real time for that. I looked a bit into sending the video packets via UDP, but that would create the challenge of having to know the IP address of the device. Not to mention the overhead of re-assembling the packets into video frames and keeping them somewhat synced. And althought the max. possible size of UDP datagramms is about 65K, the wireless router needs to be configures to handle jumbo-sized packets as well. Hmmm. There must be a simpler way… As this is only on a local network, and only intended for one recipent, I was wondering, whether the network speed would be high enough to deliver 25fps via a plan Apache server..? I made a simple Max patch, that would capture the video and write a jpeg image every 40ms, this should give us 25fps. Of course this can be done with any other software as well. If you think that might be to much strain on the harddisk, have a look on how to set up a RAM Disk on arbitraty mountpoint, for example in your local webserver directory. So we have our webserver, our live-update image: 192.168.20.117/live.jpg Viewing it in a browser an refreshing it should give you updated images. So far so good. (Of course, the address is my local address, yours might vary.) Now, basically all we have to do is to make a simple iPhone Appli, ask it to reload the image periodically and display the image. – create a NSURLConnection and point it to the image address – collect the data, and display it once the download is completed – download the image again after 40ms. What can I see, I am surprised it works quite well. Clearly there are some troubles: about 1% of the returned images feature not data, which would result in a flicker on the iPhone… A simple test, whether the received [data length] > 0 takes care of that problem. I am guessing, that this is caused by a collision of the write time of the max patch and the download time of the iPhone application, but I am not 100% sure. If anyone knows the answer, let me know. And, yeah, I should really make a videp demo-ing that… Anywhere, here are the juicy bits of the code:
- (void)loadView {
	[super loadView];
	NSLog(@"start");
		
	reloadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480, 320)];
	reloadImageView.center = CGPointMake(160.0, 240.0);
	reloadImageView.transform = CGAffineTransformMakeRotation(M_PI/2);

	[self.view addSubview:reloadImageView];

	self.view.backgroundColor = [UIColor blueColor];
	
	[reloadImageView release];
	
	struct timeval tv;
	gettimeofday(&tv, NULL);
	diff = tv.tv_sec;
	
	[self downloadImage];
}

- (void)downloadImage {
	startTimestamp = [self currentTime];

	NSString *address = @"http://192.168.20.117/live.jpg";

	NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:address]];
	[NSURLConnection connectionWithRequest:request delegate:self];
}


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	downloadErrors++;
	[self downloadImage];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	//NSLog(@"didReceiveResponse");
	data = nil;													// clear
	[data release];												// release
	data = [[NSMutableData alloc] initWithCapacity:20000];		// create & retain
	
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)partialData {
	//NSLog(@"didReceiveData");
	[data appendData: partialData];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	//NSLog(@"connectionDidFinishLoading");
	
	float difference = (([self currentTime] - startTimestamp) - 0.040);
	if ([data length] > 0) {
		// check if data has content (displaying an empty data 
		// images shows nothing, but flashes the background)
		reloadImageView.image = [UIImage imageWithData:data];
		imagesDownloaded++;
		totalBytes += [data length];
	} else {
		zeroBytes++;
	}

	if (difference < 0) {
		[self performSelector:@selector(downloadImage) withObject:nil afterDelay:fabs(difference)];
	} else {
		[self downloadImage]; // loop
	}

}

- (float)currentTime {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	float msec = tv.tv_usec / 1000000.0;
	float current = (tv.tv_sec - diff) + msec;
	return current;
}

And here is the whole demo Xcode project. Make sure to change the image address to your local image. I also include a simple Max-patch, that saves images from a camera to disk. Update Although the initial diff timer was in the sniplet here, it did not make it in the original Xcode project. Mistake corrected, now the Xcode project should reflect the code here.

303singleTap: and private API

Very funny and strange case of rejection. I made a method called ‘singleTap’, that is – as the name suggests – receiving events after a single tap occurs. During the development process the function was not used and commented out, but an oversight let to the notification being left it. And then the message from Apple:
“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.” The following non-public API is included in your application: singleTap:
Hmm. Clearly I did not use a private API, apparently I just happened to call a function the same name as a private API function… Wondering if there is a list of reserved function names, which is triggered a rejection? Solution? I commented out the superflicial notification AND renamed the function to ‘oneTap’. Just in case. I am starting to believe the stories about the Apple store.

162iPhone: Dynamic Table Heights

Nice blog from CIMGF on Dynamic Table Heights. http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/

148iPhone: Checking Network Availability

Checking whether network is present and active. By way of: http://70.40.216.232/forums/viewtopic.php?f=21&t=425 UIApplication-Network.h

//
//  UIApplication-Network.h
//
//  SystemConfiguration.framework will need to be added to your project
//
//  To use just call as a class function [UIApplication hasNetworkConnection]
//

#import 
#import 


@interface UIApplication (NetworkExtensions)

+(BOOL)hasActiveWiFiConnection;     // fast wi-fi connection
+(BOOL)hasNetworkConnection;     // any type of internet connection (edge, 3g, wi-fi)

@end
UIApplication-Network.m
//
//  UIApplication-Network.m
//

#import "UIApplication-Network.h"


@implementation UIApplication (NetworkExtensions)

#define ReachableViaWiFiNetwork          2
#define ReachableDirectWWAN               (1 << 18)
// fast wi-fi connection
+(BOOL)hasActiveWiFiConnection
{
	SCNetworkReachabilityFlags     flags;
	SCNetworkReachabilityRef     reachabilityRef;
	BOOL                              gotFlags;
	
	reachabilityRef     = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.apple.com" UTF8String]);
	gotFlags          = SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
	CFRelease(reachabilityRef);
	
	if (!gotFlags)
	{
		return NO;
	}
	
	if( flags & ReachableDirectWWAN )
	{
		return NO;
	}
	
	if( flags & ReachableViaWiFiNetwork )
	{
		return YES;
	}
	
	return NO;
}

// any type of internet connection (edge, 3g, wi-fi)
+(BOOL)hasNetworkConnection;
{
    SCNetworkReachabilityFlags     flags;
    SCNetworkReachabilityRef     reachabilityRef;
    BOOL                              gotFlags;
    
    reachabilityRef     = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.apple.com" UTF8String]);
    gotFlags          = SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
    CFRelease(reachabilityRef);
    
    if (!gotFlags || (flags == 0) )
    {
        return NO;
    }
    
    return YES;
}

@end

Also, don't forget to add the SystemConfiguration.framework to the Frameworks folder in your application. In case you get errors like that:
		  
"_SCNetworkReachabilityGetFlags", referenced from:
		      +[UIApplication(NetworkExtensions) hasActiveWiFiConnection] in UIApplication-Network.o
		      +[UIApplication(NetworkExtensions) hasNetworkConnection] in UIApplication-Network.o
		  "_SCNetworkReachabilityCreateWithName", referenced from:
		      +[UIApplication(NetworkExtensions) hasActiveWiFiConnection] in UIApplication-Network.o
		      +[UIApplication(NetworkExtensions) hasNetworkConnection] in UIApplication-Network.o
		ld: symbol(s) not found
		collect2: ld returned 1 exit status
Build failed (2 errors)
Picture 4

119Updating to OS 3.0 from beta 5

Apparently has to be put into recovery mode. http://discussions.apple.com/thread.jspa?messageID=9651285 http://support.apple.com/kb/HT1808

438VVOSC – Objective C OSC wrapper

source: http://github.com/mrRay/vvosc/tree/master docs: http://www.vidvox.net/rays_oddsnends/vvosc_doc/ after following the instructions in the docs, i get the following error (iPod Touch 2nd, OS3.0 beta 5)
/Users/username/Desktop/Test/build/Debug-iphoneos/Test.app: object file format invalid or unsuitable
After some googling, I came across this, and it seems to do the trick. add: $(SDKROOT)/ResourceRules.plist to the Code Signing Resource Path. Why exactly it’s working is anybody’s guess. ~ This might also be worth a look: liblo: Lightweight OSC implementation