• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
занятие8
 

занятие8

on

  • 827 views

 

Statistics

Views

Total Views
827
Views on SlideShare
827
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

занятие8 занятие8 Presentation Transcript

  • Разработка приложений для iPhone и iPad занятие #8
  • песочница
  • а что внутри?Home Directory Layout• Each app has its own set of directories я!• <Application Home> ельз ! MyApp.app т ьн е ня ! MyApp -м ! MainWindow.nib ! SomeImage.png ! Documents - добавления здесь! ! Library ! Caches ! Preferences• Applications only read and write within their home directory• Backed up by iTunes during sync (mostly)
  • File Paths in Your Application File Paths in Your Application // Basic directories путь к документам NSString *homePath = NSHomeDirectory(); // Basic directories NSTemporaryDirectory(); NSString *tmpPath = NSString *homePath = NSHomeDirectory(); // Documents directory NSString *tmpPath = NSTemporaryDirectory(); NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); // Documents directory NSArray *paths = NSSearchPathForDirectoriesInDomains NSString *documentsPath = [paths objectAtIndex:0]; (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; // <Application Home>/Documents/foo.plist NSString *fooPath = // <Application stringByAppendingPathComponent:@“foo.plist”]; [documentsPath Home>/Documents/foo.plist NSString *fooPath = [documentsPath stringByAppendingPathComponent:@“foo.plist”];Tuesday, February 2, 2010 1Tuesday, February 2, 2010 16
  • SQLite!• база в файле• нет сервера• простая реализация• включена в iPhone
  • 6 шагов• находим файл базы• подключаемся - sqlite3_open• создаем запрос• готовим, проверяем - sqlite3_prepare_v2• выполняем - sqlite3_step• завершаем - sqlite3_finalize• закрываем - sqlite3_close
  • шаг 0 - создать БД$ sqlite3 ex1SQLite version 3.6.11Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> create table tbl1(one varchar(10), two smallint);sqlite> insert into tbl1 values(hello!,10);sqlite> insert into tbl1 values(goodbye, 20);sqlite> select * from tbl1;hello!|10goodbye|20sqlite>
  • подготовка #import <sqlite3.h> NSString *databaseName = @"Cocktails.sql"; NSArray *documentPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *databasePath = [documentsDirstringByAppendingPathComponent:databaseName]; BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; success = [fileManager fileExistsAtPath:databasePath]; if(!success) { NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; [fileManager release]; }
  • чтениеsqlite3 *database; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { const char *sqlStatement = "select * from cocktail;"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) ==SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { int anId = sqlite3_column_int(compiledStatement, 0); NSString *aName = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiledStatement, 1)]; //... } } sqlite3_finalize(compiledStatement); } sqlite3_close(database);
  • запись• просто sqlite3_step(compiledStatement), при удаче - SQLITE_DONE
  • GoogleMaps API Facebook API Яндекс Карты APITwitter API общение с вашим сервером
  • xml<?xml version="1.0" encoding="UTF-8" ?><painting> <img src="madonna.jpg" alt=Foligno Madonna, byRaphael/> <caption>This is Raphaels "Foligno" Madonna, painted in <date>1511</date>–<date>1512</date>. </caption></painting>
  • xml NSURL *xmlURL = [NSURL URLWithString:URL]; NSXMLParser * rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; [rssParser setDelegate:self]; [rssParser parse];- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qNameattributes:(NSDictionary *)attributeDict- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string- (void)parserDidEndDocument:(NSXMLParser *)parser {
  • What does a JSON object look like? json { “instructor” : “Josh Shaffer”, “students” : 60, “itunes-u” : true, “midterm-exam” : null, “assignments” : [ “WhatATool”, “HelloPoly”, “Presence” ] } • NSDictionary *result = [jsonString JSONValue];y, February 2, 2010 41
  • http://empatika.comoleg.parinov@empatika.com