helloworld
推薦 iPhone & iPad App 開發參考書 / dev books
![]() |
iPhone.and.iPad.Apps.for.Absolute.Beginners(Apress.2010-05) |
我的第一隻 iPhone 程式 – HelloMap !
這隻程式會展現一個地圖, 並以目前定位的座標為中心點, 及一個按鈕,按下按鈕會把座標及UDID傳送到 server , 由 server 端的程式記錄下來, 並且 server 端亂數送出一個水果名回傳給 iPhone client 端, iPhone client 端再把這水果名 show 在 iPhone screen上.
底下是片斷程式碼:
FirstViewController.h :
#import
#import
#import
@interface FirstViewController : UIViewController {
IBOutlet MKMapView *mapView;
CLLocationManager *locationManager;
CLLocation *currentLocation;
}
- (IBAction) updateLocation;
@end
FirstViewController.m :
- (void)viewDidLoad {
[super viewDidLoad];
if (locationManager==nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
}
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"Location : %.6f , %.6f", newLocation.coordinate.latitude , newLocation.coordinate.longitude );
MKCoordinateRegion region = [mapView region];
region.center = newLocation.coordinate;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
region.span = span;
[mapView setRegion:region animated:TRUE];
//
if ( currentLocation != nil) {
[currentLocation release];
currentLocation = nil;
}
currentLocation = [newLocation copy];
}
- (IBAction) updateLocation {
if(currentLocation==nil)
return;
UIDevice *device=[[UIDevice alloc] init];
NSString *URLString=[[NSString alloc] initWithFormat:@"http://z.monster.tw/save_location.php?lat=%.6f&lng=%.6f&id=%@"
,currentLocation.coordinate.latitude
,currentLocation.coordinate.longitude
,device.uniqueIdentifier];
[device release];
NSLog(@"%@",URLString);
// Send Request
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:20.0];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
// Display AlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:returnString message:@"Thanks!"
delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil];
[alert show];
[alert release];
[returnString release];
}
[導覽] 有趣的 iPad iPhone development video 教學
From : Rory Lewis, PhD, JD
URL : http://www.rorylewis.com/docs/02_iPad_iPhone/05_iPhoneTutorials.htm
另外給初接觸 objective-c 的介紹:
URL : http://maciku.blogspot.com/2009/12/iphone-objective-c.html
中文開發網站 : http://www.cocoachina.com/iphonedev/
// ——————
obj->method(argv);
[obj method: argv];
// ——————
@implementation HelloController
- (IBAction)sayHello:(id)sender {
[destinationTextField setStringValue:[sourceTextField stringValue]];
}
@end
(id)sender 是一個可以選擇性的用法,若您有需要取得發出 IBAction的元件時,可以用這個 sender變數來取得.但記得可能需要 cast一下.
UIButton *senderButton=(UIbutton*) sender;[senderButton setHidden: YES];
這樣就會把該button隱藏起來.
// ——————
[2010/7/9 下午 04:48:25] Rimmon 2.0: jason 有 mac os 的 sftp GUI 的 tools 嗎?
[2010/7/9 下午 04:48:40] Rimmon 2.0: 想要用 tools 傳 code 比較方便
[2010/7/9 下午 04:51:05] _RTN Jason Chen: http://www.versiontracker.com/dyn/moreinfo/macosx/15693
[2010/7/9 下午 04:51:08] _RTN Jason Chen: Fugu
[2010/7/9 下午 04:51:35] _RTN Jason Chen: www.versiontracker.com 有非常多的 OSX 軟體可下載
[2010/7/9 下午 04:53:59] _RTN Jason Chen: 還有 Microsoft Remote Desktop Connection 可遠端遙控 Windows
[2010/7/9 下午 04:55:13] _RTN Jason Chen: smb://172.30.0.29/Install 這樣 OSX 才看得懂網路分享目錄
[2010/7/9 下午 05:00:10] _RTN Jason Chen: Finder, 用 apple鍵 + K 再輸入 cifs://172.30.0.19/Install 即可連 server shared
[c code] 檢查某檔案是否存在 – check file exists using C
♥ ♥ ♥ 如果這頁訊息對您有幫助 請幫我點上方廣告↑ ↑ ↑ 感謝您的幫助 ♥ ♥ ♥
FILE* fp = fopen(path, "r");
if (fp) {
// file exists
fclose(fp);
} else {
// file doesn't exist
}
