そのため、現在のプロジェクトでは、大量のデータを含む大きなテキストファイルをダウンロードします。次に、そのファイルを検索して、ユーザーが入力した番号が含まれているかどうかを確認する必要があります。Objective-cでは、これは次のようになります。
NSString *securityCodeData = [[NSUserDefaults standardUserDefaults] stringForKey:@"securityCodeData"];
NSString *trackTraceFileUrlName = [NSString stringWithFormat:@"http://plex.janssen1877.com/app/life/%@",securityCodeData];
NSData *tmpData = [NSData dataWithContentsOfURL:[NSURL URLWithString:trackTraceFileUrlName] ];
//convert data to string
NSString *tmpString = [[NSString alloc] initWithData:tmpData encoding:NSUTF8StringEncoding];
NSArray *piecesArray = [tmpString componentsSeparatedByString:@"\n"];
NSMutableArray *trackTraceContent = [NSMutableArray arrayWithArray:piecesArray];
NSLog(@"RAW:%@",trackTraceContent);
/*Filtering array for referance*/
NSPredicate *findStringWithReference = [NSPredicate predicateWithFormat:@"SELF CONTAINS [cd] %@",cRText.text];
NSArray *trackTraceContentFiltered = [trackTraceContent filteredArrayUsingPredicate:findStringWithReference];
NSLog(@"Filtered:%@",trackTraceContentFiltered);
if ([trackTraceContentFiltered count] == 0) {
UIAlertView *invalidCode = [[UIAlertView alloc] initWithTitle:@"Enter a valid reference number!"
message:@"Please enter a valid reference number so we can provide the correct information for you."
delegate:nil
cancelButtonTitle:@"Close"
otherButtonTitles:nil];
[invalidCode show];
}
monoTouchでこれを行うための最良の方法は何でしょうか?私はすでにいくつかのコードを試しましたが、それでも正しくありません:
void GetTrackTraceData ()
{
//Collecting Trace and Trace data from link + security code and converting Track and Trace data into string
string TracTraceDataString = NSString.FromData (NSData.FromUrl
(NSUrl.FromString ("http://plex.janssen1877.com/app/life/" + NSUserDefaults.StandardUserDefaults ["SecurityToken"])),
NSStringEncoding.UTF8);
//Seperating the string and putting each object in the
string[] TrackTraceDataArray = TracTraceDataString.Split (new char[] { '\n' });
var TrackTraceFilteredArray = TrackTraceDataArray.Where (x => x.Contains (RefNr.Text));
if (TrackTraceFilteredArray == null) {
UIAlertView InvalidAlert = new UIAlertView ("Reference number invalid", "The reference number that you have entered is not linked to the current security code. You can change your security code in the settings.", null, "OK", null);
InvalidAlert.Show ();
}else{
this.PerformSegue ("PushToTrackTraceDetails", this);
}
foreach (string s in TrackTraceFilteredArray)
Console.WriteLine (s);
}
TrackTraceFilteredArrayが何らかの理由でnullになることはありません。または、これを別の方法で実装する必要がありますか?このコードは正しく書かれていますか?私はc#/ MonoTouchを初めて使用するので、最適化を使用できると思います。テキストファイルに保存されているデータの例を次に示します。
51405199 0001055479 1302180721 210005 dossier aangemaakt EDI
51403415 0001049498 1302150503 TOMTOM101 Order 51403415-3-278065601: ontvangen
51403415 0001049498 1302151106 TOMTOM241 Order 51403415-3-278065601: gestart
51403415 0001049498 1302151106 TOMTOM249 Order 51403415-3-278065601: voltooid
51403577 0001051919 1302150503 TOMTOM101 Order 51403577-3-278065601: ontvangen
51403577 0001051919 1302151027 TOMTOM241 Order 51403577-3-278065601: gestart
51403577 0001051919 1302151039 TOMTOM241 Order 51403577-3-278065601: geschatte aankomst 10:57, 18 km op be
51403577 0001051919 1302151106 TOMTOM249 Order 51403577-3-278065601: voltooid
51404608 EK1000204732540 1302151708 TOMTOM101 Order 51404608-2-477100892: ontvangen
51404608 EK1000204732540 1302151708 TOMTOM101 Order 51404608-3-477100892: ontvangen
51404772 0001052637 1302150520 210005 dossier aangemaakt EDI
51404772 0001052637 1302151732 TOMTOM101 Order 51404772-3-278065684: ontvangen
51404773 0001052688 1302150520 210005 dossier aangemaakt EDI
51404773 0001052688 1302151732 TOMTOM101 Order 51404773-3-278065684: ontvangen
51404774 0001053872 1302150521 210005 dossier aangemaakt EDI
51404775 0001053872 1302150521 210005 dossier aangemaakt EDI
51404776 0001052689 1302150521 210005 dossier aangemaakt EDI
51404777 0001052690 1302150530 210005 dossier aangemaakt EDI
51404778 0001053934 1302150630 210005 dossier aangemaakt EDI
51404778 0001053934 1302151733 TOMTOM101 Order 51404778-3-278065681: ontvangen
51404779 0001053934 1302150630 210005 dossier aangemaakt EDI
51404779 0001053934 1302151733 TOMTOM101 Order 51404779-3-278065690: ontvangen
51404780 0001053934 1302150630 210005 dossier aangemaakt EDI
51404780 0001053934 1302151733 TOMTOM101 Order 51404780-3-278065691: ontvangen