इंटरनेट से कनेक्ट होने पर स्थानीय डीबी पर वेब सर्वर पर संग्रहीत ऑफ़लाइन डेटा भेजने वाले ऐप को लागू करने का प्रयास करना। मैं नीचे दिखाए गए कोड का उपयोग करता हूं। जहां तक मैंने परीक्षण किया है, यह ठीक काम करता है, सुनिश्चित नहीं है कि यह बड़ी संख्या में रिकॉर्ड्स के लिए ठीक काम करेगा। मैं जानना चाहता हूं कि इस कोड पर कोई ट्वीकिंग प्रदर्शन को बढ़ा सकता है ???(आईओएस) ऑफलाइन सिंक डीबी - सर्वर
नोट
- मैं इस ऑफ़लाइन समन्वयन उद्देश्य के लिए एक सबसे खराब कोड होगा पता है, तो यह बेहतर बदलाव करने कोशिश कर रहा।
ऐप से सर्वर तक, यह एकमात्र तरीका सिंक्रनाइज़ेशन है।
-(void)FormatAnswersInJSON { DMInternetReachability *checkInternet = [[DMInternetReachability alloc] init]; if ([checkInternet isInternetReachable]) { if ([checkInternet isHostReachable:@"www.apple.com"]) {//Change to domain responseArray = [[NSMutableArray alloc] init]; dispatch_async(backgroundQueue, ^(void) { NSArray *auditIDArray = [[NSArray alloc] initWithArray: [self getUnuploadedIDs]]; for (int temp = 0; temp < [auditIDArray count]; temp ++) { // Code to post JSON to server NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; if (!error) { NSString *responseID = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; if ([responseID isEqualToString:@"ERROR"]) { //Error uploading records } else { [responseArray addObject:responseID]; } } else { //Error return; } } dispatch_async(backgroundQueue, ^{ /* Based on return code update local DB */ for (int temp = 0; temp < [responseArray count]; temp ++) { [self updateRecordsForID:[auditIDArray objectAtIndex:temp] withID:[responseArray objectAtIndex:temp]]; } }); }); } } } - (void)upload { //Called when internet connection available if(backgroundQueue){ dispatch_suspend(backgroundQueue); dispatch_release(backgroundQueue); backgroundQueue = nil; } backgroundQueue = dispatch_queue_create("com.XXXX.TestApp.bgqueue", NULL); dispatch_async(backgroundQueue, ^(void) { [self FormatAnswersInJSON]; }); }
यदि आप एक्स आइटम अपलोड करते हैं, तो सर्वर एक त्रुटि फेंकता है, तो आप अपने स्थानीय डीबी को अपडेट नहीं करेंगे। क्या मैने इसे सही समझा? हो सकता है कि बदले में इसके बदले में तोड़ दें, ताकि आप अपने स्थानीय डीबी को सफल होने के लिए अपडेट कर सकें। – 7usam
हां। आप यह यही समझे। मैं इसे बदल दूंगा !! – Nina
@ 7usam सत्य, जब तक विफलता होती है तो रोलबैक परिवर्तनों के लिए महत्वपूर्ण नहीं है; "सब कुछ या कुछ नहीं" दृष्टिकोण। – Sam