Archive for the ‘iPhone’ Category

NSData+util category

Saturday, November 1st, 2008

.h file:

#import <Foundation/Foundation.h>
 
@interface NSData (NSData_HexAdditions)
- (NSString*) stringWithHexBytes;
+ (NSString*) sha256HashFromString:(NSString*)string;
+ (NSString*) sha256HashFromData:(NSData*)data;
 
@end



.m file:

#import "NSData+Util.h"
#import <CommonCrypto/CommonDigest.h>
 
@implementation NSData (NSData_HexAdditions)
- (NSString*) stringWithHexBytes {
	NSMutableString *stringBuffer = [NSMutableString
									 stringWithCapacity:([self length] * 2)];
	const unsigned char *dataBuffer = [self bytes];
	int i;
 
	for (i = 0; i < [self length]; ++i)
		[stringBuffer appendFormat:@"%02x", (unsigned long)dataBuffer[ i ]];
 
	return [[stringBuffer copy] autorelease];
}
 
+ (NSString*) sha256HashFromData:(NSData*)data
{
	return [NSData sha256HashFromString:[NSString stringWithCString:(const char*)[data bytes] length:[data length]]];
}
 
+ (NSString*) sha256HashFromString:(NSString*)string
{
	unsigned char hashedChars[CC_SHA512_DIGEST_LENGTH];
 
	CC_SHA512([string UTF8String],
			  [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 
			  hashedChars);
	NSData * hashedData = [NSData dataWithBytes:hashedChars length:CC_SHA512_DIGEST_LENGTH];	
	NSData* tmp = [[NSData alloc] initWithData:hashedData];
	NSString* ret = [tmp stringWithHexBytes];
	[tmp release];
	return ret;
}
@end

Generate random cryptographic hash from NSString

Saturday, November 1st, 2008

Implementation .m file:

#import "NSString+Hash.h"
 
 
@implementation NSString (Hash)
 
 
+(NSString*)randomSaltWithLength:(int)length
{
	char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	NSMutableString* ret = [[[NSMutableString alloc] initWithCapacity:length] autorelease];
	srandomdev();
 
	for(int i=0;i<length;i++)
	{
		int index = random()%52;
		char a = chars[index];
		[ret appendString:[NSString stringWithCString:&a length:1]];
	}
 
	return ret;
}
 
@end





.h file:

@interface NSString (Hash) 
 
+(NSString*)randomSaltWithLength:(int)length;
 
@end

UIAlertView with UIProgressView or UIActivityIndicator

Saturday, November 1st, 2008

http://discussions.apple.com/thread.jspa?messageID=8215707

- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
  progressAlert = [[UIAlertView alloc] initWithTitle: message
                                             message: @"Please wait..."
                                            delegate: self
                                   cancelButtonTitle: nil
                                   otherButtonTitles: nil];
 
 
  // Create the progress bar and add it to the alert
  if (activity) {
    activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
    [progressAlert addSubview:activityView];
    [activityView startAnimating];
  } else {
    progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
    [progressAlert addSubview:progressView];
    [progressView setProgressViewStyle: UIProgressViewStyleBar];
  }
  [progressAlert show];
  [progressAlert release];
}

Using Bonjour for iPhone/desktop application sync

Sunday, July 27th, 2008

http://cocoa-nut.de/?p=27

Petition to lift iPhone SDK NDA

Wednesday, July 23rd, 2008

http://www.ipetitions.com/petition/iPhoneNDA

I don’t know why this NDA is still here with the app store and 2.0 being out there.

iPhone SDK NDA?

Friday, July 18th, 2008

Why is the iPhone SDK still under NDA?  What’s to keep secret.  This is only hurting developers and especially new developers.  No one can share any experiences with each other on how to develop from this phone.  Obviously many people want to ask questions about it since there are at least 1 post or more on the cocoa-dev mailing list per day.

 

I’m sure the moderators would love to not have to copy and paste the “iPhone is still under NDA” drivel into all these posts.

Bypass Objective-C’s message passing for performance

Thursday, May 29th, 2008

http://blogs.ittoolbox.com/emergingtech/macsploitation/archives/follow-up-to-bypassing-objectivecs-message-passing-mechanism-25012

Load image from URL into UIImageView

Wednesday, May 7th, 2008
NSString* mapURL = [theURLString stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
 
UIImage* image = [[UIImage alloc] initWithData:imageData];
[imageView setImage:image];
[imageData release];
[image release];

Link to libxml in Cocoa for iPhone development

Sunday, April 20th, 2008

libxml on the iPhone