-
Recent Entries
- Maha 0.9.2 May 29th, 2011 One comment
- Upload Image to img.ly February 28th, 2011 No comments
- 不讓app hang起來的頹廢方法 January 13th, 2011 No comments
- MGTwitterEngine on iOS November 29th, 2010 No comments
- Setting.app裡面的app settings要注意耶 October 15th, 2010 One comment
-
Recent Comments
- Very nice indeed, looking forward to it. ... On Maha 0.9.2
Upload Image to img.ly
- Content-Type: image/jpeg , I used ASIHttpRequest which uses application/octet-stream as the default content-type, so the solution is
[request setData:UIImageJPEGRepresentation(picture, 0.8) withFileName:@"filename.jpg" andContentType:@"image/jpeg" forKey:@"media"];
- User-agent, this is super weird. Using “Maha 1.0 (iPhone Simulator; iPhone OS 4.2; en_US)” as the user agent, which is the default, makes me fail. But if I copy Twitterific’s user agent “Twitterrific/4.0 CFNetwork/454.11.5 Darwin/10.6.0 (i386)”, it works like a charm. So my solution is
[request addRequestHeader:@"User-Agent" value:@"Maha/1.0 CFNetwork/454.11.5 Darwin/10.6.0 (i386)"];
And everything works now, tho I don’t know what was the real problem.
不讓app hang起來的頹廢方法
終於用了一次之前 @moming2k 很喜歡的dispatch_async
好棒好棒
簡單點來說吧,首先要
#include <dispatch/dispatch.h>之後會hang住的東西丟到裡面去就ok了
dispatch_queue_t gQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(gQueue, ^{ ////丟到這裡來 });
如果你喜歡的話可以做一條queue
dispatch_queue_t myQueue = dispatch_queue_create("com.mycompany.myqueue", 0);
不過一般來說用default的都ok吧
MGTwitterEngine on iOS
對於我這種根基不太好的人來說要setup這個簡直是超麻煩耶
一直都是在github下載然後drag進去project就好了,但這個需要YAJL,OAuthConsumer,TouchJSON呢
首先,OAuthConsumer,TouchJSON都不難入手,跟平常一樣對待就ok了,問題是YAJL
這個直接上來說不能在iOS上跑耶
所以應該用這個:https://github.com/gabriel/yajl-objc
跟著instructions一路set好就沒問題了,
然後去MGTwitterEngineGlobalHeader.h改一下
#define YAJL_AVAILABLE 1 #define TOUCHJSON_AVAILABLE 1
很好很不錯!
Setting.app裡面的app settings要注意耶
我看到plist裡面有個叫DefaultValue就以為會幫我handle埋default的情況於是好興奮的去用了
結果原來是,未設定過的話 [[NSUserDefaults standardUserDefaults] whateverForKey:]會return nil
仲要係若無其事的感覺,因為我沒看doc的關係抵死XD
於是以下是解決方法:http://www.btjones.com/2010/05/nsuserdefaults-nil-setting-problem/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | - (void)setupDefaults { //get the plist location from the settings bundle NSString *settingsPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Settings.bundle"]; NSString *plistPath = [settingsPath stringByAppendingPathComponent:@"Root.plist"]; //get the preference specifiers array which contains the settings NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath]; NSArray *preferencesArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"]; //use the shared defaults object NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; //for each preference item, set its default if there is no value set for(NSDictionary *item in preferencesArray) { //get the item key, if there is no key then we can skip it NSString *key = [item objectForKey:@"Key"]; if (key) { //check to see if the value and default value are set //if a default value exists and the value is not set, use the default id value = [defaults objectForKey:key]; id defaultValue = [item objectForKey:@"DefaultValue"]; if(defaultValue && !value) { [defaults setObject:defaultValue forKey:key]; } } } //write the changes to disk [defaults synchronize]; } |
適當的在application:didFinishLaunchingWithOptions: 裡面觸發就很好了
iphone os 3 和iOS4的 CLLocation getDistanceFrom: 和 distanceFromLocation:
終於遇到第一次轉版本上的問題,其實內容都沒什麼大不了,只是method名轉了
google到了的各種解決方法中最喜歡這個:
http://0xced.blogspot.com/2010/09/cllocation-getdistancefrom-vs.html
1 2 3 4 5 6 7 | main.m #import <objc/runtime.h> Method getDistanceFrom = class_getInstanceMethod([CLLocation class], @selector(getDistanceFrom:)); class_addMethod([CLLocation class], @selector(distanceFromLocation:), method_getImplementation(getDistanceFrom), method_getTypeEncoding(getDistanceFrom)); |
好帥

