2012-04-03 2 views
1

저는 데이터베이스와 통신하고있는 웹 앱을 만들고 있습니다. 웹 응용 프로그램이 내 데이터베이스에서 모든 정보를 다운로드하고 로컬로 저장하여 (사용자가 오프라인 인 경우에도) 액세스하여 편집 할 수 있도록하고 로컬로 다시 동기화합니다 (사용자가 온라인 상태 일 때).iPhone의 로컬 저장소를 사용하여 데이터 저장 - 어떤 방법으로 가나 요?

내 데이터베이스의 모든 행은 2 개의 문자열과 3 개의 정수로 구성되어 있으며 데이터베이스에 약 1000-1500 개의 행이 있습니다 (내 데이터베이스 크기에 대한 아이디어를 줄 수 있습니다).

그래서 가장 좋은 방법은 무엇입니까? 사용자 장치에 이런 종류의 데이터를 어떻게 든 캐시 할 수 있습니까? JSON을 통해 데이터베이스를 검색하고 사용자가 액세스하고 작업 할 수있는 자바 스크립트 배열에 로컬로 저장하는 것 (언급 한 것처럼 나중에 부분은 사용자가 오프라인 일지라도 작동 할 수 있어야 함)과 같습니다. 이것에 대한 모든 입력은 크게 감사드립니다. 나는 적어도 여기에 올바른 방향으로 생각하고 있는가?

편집 : 웹 앱으로 작업하고 있음을 명확히 밝힙니다. HTML, CSS 및 자바 스크립트로 devoloped 응용 프로그램. 나는 네이티브 목표 C iOS 앱을하고 있지 않다.

+1

Look into SQLite. 이 프레임 워크는 XCode에 포함되어 있습니다. libsqlite3.0.dylib – PaulG

+0

새로운 [데이터 저장 지침] (https://developer.apple.com/icloud/documentation/data-storage/)을 반드시 준수하십시오. 당신이하지 않으면 당신은 꽤 가혹하게 때려 눕습니다. –

+0

얘들 아, 나는 단지 내가 웹 앱으로 일하고 있음을 분명히하고 싶다. HTML, CSS 및 자바 스크립트로 devoloped 응용 프로그램. 나는 네이티브 목표 C iOS 앱을하고 있지 않다. – nalas

답변

0

웹 기술을 사용하여 모바일 앱을 개발하는 경우 데이터를 저장하는 가장 좋은 방법은 SQLite를 사용하는 것입니다. 오프라인 또는 온라인 모드로 데이터를 저장하고 검색 할 수 있습니다. 또 다른 장점은 네이티브로 이동하기로 결정한 경우 데이터베이스를 모든 모바일 장치 또는 데스크톱 응용 프로그램으로 이식 할 수 있다는 것입니다.

더 많은 질문이 있거나 도움이 필요하면 저에게 연락하여 웹 기술로 SQLite를 사용하는 방법에 대한 정보를 얻을 수 있습니까?

모바일 앱용 웹 GUI 설계시 시간을 절약하려면 모바일 웹 프레임 워크를 사용할 수 있습니다. 개발 시간이 단축되고 기기의 일부 기본 API에 액세스 할 수 있습니다. 나는 Sencha를 추천한다 : http://www.sencha.com/products/touch/ (Html5, JS, CSS3에 정말 좋은 기본 프레임 워크)

0

Core Data (SQLite를 사용)을 사용해야합니다.

+0

그건 완전히 사실이 아닙니다. 핵심 데이터는 그렇게 정의한 경우 SQLite를 백업 스토어로 사용합니다. 핵심 데이터와 함께 사용할 수있는 여러 상점이 있습니다. 상점을 정의하지 않는 것과는 달리 기본적으로 SQLite를 사용합니다. 이것은 명시 적으로 설정되어야합니다. – jmstone617

0

지속성을 조사해야하며 그 중 가장 좋은 옵션은 핵심 데이터입니다. 퍼시스턴스를 제외하고는 다른 사람들이 herehere 등으로 윤곽을 그렸던 많은 다른 큰 이점을 얻을 수 있습니다. 앞서 언급했듯이 SQLite를 앱의 보조 저장소로 사용할 수 있으며 원하는 경우 엔트리의 개체 표현에 액세스 할 수 있습니다. 동기화를 다루는 경우 iCloud를 살펴보고 here에 대한 정보를 찾을 수 있습니다.

+0

저는 HTML, CSS 및 자바 스크립트로 devoloped 된 웹 애플리케이션으로 작업하고 있음을 분명히 밝힙니다. 나는 네이티브 목표 C iOS 앱을하고 있지 않다. 너 무슨 소리 야? – nalas

+0

예, 이것은 네이티브 구성 요소가있는 응용 프로그램을 작성 중이라고 가정합니다. – jmstone617

2
make a class of NSObject 

@interface abc : NSObject<NSCoding> 

@property..... // add properties that you want to save 

-(void)initWithDictionary:(NSMutableDictionary *)dictionary; // override init by passing dictionary with values of your properties 

@end 

in abc.m file 

implement these functions 

-(void)initWithDictionary:(NSMutableDictionary *)dictionary 
{ 

    yourProperty=[dictionary valueForKey:@"propertyKey"]; 

} 

-(void) encodeWithCoder:(NSCoder *)aCoder{ 

    [aCoder encodeObject:yourProperty forKey:@"propertyKey"]; 

} 

-(id) initWithCoder:(NSCoder *)aDecoder{ 

    self =[super init]; 

    if(self){ 

     [self setyourProperty:[aDecoder decodeObjectForKey:@"yourProperty"]]; 

    } 
    return self; 
} 


now make a shared class that can be accessed from anywhere 

@interface xyz : NSObject 
{ 
    NSMutableArray *allItems; 
} 

+(xyz *) sharedStore; 

-(NSMutableArray *)allItems; 

-(abc *) createItem:(NSMutableDictionary *)dictionary; 

-(NSString *) saveItemPath; 

-(BOOL)saveChanges; 


now in xyz.m implement these functions 

-(id)init{ 

    self=[super init]; 

    if(self){ 

     NSString *path=[self saveItemPath]; 

     allItems=[NSKeyedUnarchiver unarchiveObjectWithFile:path]; 

     if(!allItems){ 

      allItems=[[NSMutableArray alloc]init] ;//]WithObjects:@"No more item in store", nil]; 

     } 

    } 

    return self; 
} 
+(xyz *)sharedStore{ 

    static xyz *sharedStore=nil; 

    if(!sharedStore){ 

     sharedStore=[[super allocWithZone:nil]init]; 

    } 

    return sharedStore; 

} 
+(id)allocWithZone:(NSZone *)zone{ 

    return [self sharedStore]; 

} 
-(NSArray *)allItems{ 

    //[allItems insertObject:@"No more items are in store" atIndex:[allItems count]]; 
    return allItems; 

} 

-(abc *) createItem:(NSMutableDictionary *)dictionary 
{ 
    abc *p=[[abc alloc] init]; 
    [p initWithDictionary:dictionary]; 
    [allItems insertObject:p atIndex:0]; 
    return p; 
} 

-(NSString *) saveItemPath 
{ 
    NSArray *documentdirectories=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 

    NSString * documentDirectory=[documentdirectories objectAtIndex:0]; 

    return [documentDirectory stringByAppendingPathComponent:@"items.archive"]; 

} 

-(BOOL) saveChanges 
{ 

    NSString *path=[self saveItemPath]; 

    return [NSKeyedArchiver archiveRootObject:allItems toFile:path]; 

} 


now you can use the global variable like this 

[xyz sharedStore]allItems] 

now do one more thing, add this line to application did enter background 

[xyz sharedStore]saveChanges]; 
관련 문제