• 2013-04-17

    What the hell is Apple website “Your session has timed out”!

    Views: 4012 | No Comments

    Can not log in with my Apple ID, always get an “Your session has timed out.” error message.

    Could not submit a feedback, the page https://developer.apple.com/contact/submit.php didn’t redirect properly!

    Apple, you should do better!

    Posted by ideawu at 2013-04-17 11:39:58
  • 2013-04-14

    Cocoa Objective-C JSON encode and decode

    Views: 8283 | No Comments

    KISS – Keep It Simple, Stupid!

    The NSJSONSerialization limited top level objects to NSArray and NSDcitionary, but with this tool, you can encode primative objects, such as integer, float, string, array, dictionary to JSON string, and vice verse.

    You can decode the json string contains only string to Objective-C object, like "a" to an NSString, and it works for numbers, 123 will decode to NSNumber.

    #import <Foundation/Foundation.h>
    
    NSString *json_encode(id obj){
    	BOOL is_primative = false;
    	if(![obj isKindOfClass:[NSArray class]] && ![obj isKindOfClass:[NSDictionary class]]){
    		is_primative = true;
    		obj = [NSArray arrayWithObject: obj];
    	}
    	id data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:nil];
    	NSError *err = nil;
    	NSString *str = [[NSString alloc] initWithData:data encoding:[NSString defaultCStringEncoding]];
    	if(err){
    		return nil;
    	}
    	if(is_primative){
    		str = [str substringWithRange:NSMakeRange(1, [str length]-2)];
    	}
    	return str;
    }
    
    id json_decode(NSString *str){
    	str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    	BOOL is_primative = false;
    	unichar ch = [str characterAtIndex:0];
    	if(ch == '"' || (ch != '[' && ch != '{')){
    		is_primative = true;
    		str = [NSString stringWithFormat:@"[%@]", str, nil];
    	}
    	NSData* data = [str dataUsingEncoding:[NSString defaultCStringEncoding]];
    	NSError *err = nil;
    	id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
    	if(err){
    		return nil;
    	}
    	if(is_primative){
    		obj = [obj objectAtIndex: 0];
    	}
    	return obj;
    }
    
    int main(int argc, char **argv){
    	NSArray *arr = [NSArray arrayWithObjects: @"a", @"b", nil];
    	NSLog(@"%@", json_encode(@"abc"));
    	NSLog(@"%@", json_encode(arr));
    	NSLog(@"%@", json_decode(@"[1, 2, \"abc\"]"));
    	NSLog(@"%@", json_decode(@"\"abc\""));
    	NSLog(@"%@", json_decode(@"\"%\""));
    	return 0;
    }
    

    A bunch of simpler Objective-C classes and functions(Standard Objective C Library): https://github.com/ideawu/soc

    Posted by ideawu at 2013-04-14 14:38:47
  • 2013-04-08

    Mac convert SVG to PNG

    Views: 3813 | No Comments
    qlmanage -t -s 512 -o ./output_dir file.svg
    

    -s: size in pixel
    -o: ouput dir

    Posted by ideawu at 2013-04-08 18:03:27
  • 2013-04-07

    How to deal with Xcode “Code Sign error”

    Views: 7669 | No Comments

    I happend to run into the situation that my project cannot compile and run, after I checked the “Entitlements” option. The error message is:

    "Check dependencies
    Code Sign error: The identity 'Mac Developer' doesn't match any valid, non-expired certificate/private key pair in the default keychain"
    

    I just to go to the old way to test my App, so I seek for the solution. Here is how I get rid of this error:

    1. Click on you project name from “Project Navigator”
    2. Select item under “Targets” that lies beside “Project Navigator”
    3. Then click on the “Build Settings” tab
    4. Set the option “Code Signing Identity” to “Don’t Code Sign”
    Posted by ideawu at 2013-04-07 22:42:20 Tags:
  • 2013-04-06

    How to capture ESC key in a Cocoa application?

    Views: 16699 | No Comments

    You may want to capture(or intercept, detect) the ESC key press in a Cocoa application, capture the ESC key down in Application scope for the whole app, or just in Window scope for some certain windows.

    The NSApplicationDelegate is not a subclass of NSResponder, so you can not implement the keyDown: method int app delegate. The NSWindowController is a subclass of NSResponder, you may implement keyDown: method in it, but it will not get invoked when user press the ESC key(with exceptions) and not when user is typing in a text input.

    The solution is to use a Event Monitor.

    Continue reading »

    Posted by ideawu at 2013-04-06 17:02:56 Tags:
|<<<789101112131415>>>| 11/19 Pages, 91 Results.