iPhoneアプリで作業しています。私の代理店向けのエンタープライズカレンダーアプリです。予定が入力されたWebアプリケーションにRESTful APIバックエンドが接続されています。個人の予定は、そのユーザーのiPhoneに表示されます。データはXMLで送信されます。 1日あたり3つまたは4つの予定があり、1レコードにつき10フィールド未満であるため、一度に多くのデータが転送されることはありません(選択した日の情報のみ)。iPhoneのカレンダーアプリのデータを保存するのに最適な方法
私は解析されたデータのためにiPhone上で配列を使ってこれを設計しようとしましたが、Webサーバー上のセキュリティチェックでアプリケーションのタイムアウトが発生し、非同期処理がうまく処理されませんでした。
今問題に正しく対応しているかどうかは疑問です。コアデータを使用して予定を保存し、コアデータストアをバックグラウンドで更新する方が良いでしょうか?私は、テーブルプロセスの読み込み以外のデータを更新する必要があることを知っています。私はこれに最善の方法で接近するだけで駄目です。
私はこれにアプローチする方法に関する情報についてサイトを調べました。私は本を探してみました。どんな助けもありがとう。
Security.h
typedef void (^touchIDComplete)(BOOL);
typedef void (^fileExists)(BOOL);
typedef void (^sessionVerify)(BOOL);
typedef void (^parsingData)(BOOL);
typedef void (^touchIDSuccess)(BOOL);
typedef void (^sessionRetrieved)(BOOL);
typedef void (^touchIDComplete)(BOOL);
typedef void (^sessionReading)(BOOL);
typedef void (^fillArray)(BOOL);
typedef void (^getTheData)(NSData *myData, NSError *error);
typedef void (^gettingESNBlock)(NSString *myESN, NSString *newSession, BOOL success, NSError *error);
typedef void (^checkingESNBlock)(NSString *myESN, NSString *sessionInfo, BOOL success, NSError *error);
@interface Security : NSObject
@property (strong, nonatomic) NSArray *types;
@property (strong, nonatomic) NSArray *esn;
@property (strong, nonatomic) NSString *idfv;
@property (strong, nonatomic) NSData *parseData;
@property (strong, nonatomic) NSString *sessionDetail;
@property (strong, nonatomic) NSString *loginFinished;
@property (strong, nonatomic) NSMutableURLRequest *request;
@property (atomic) NSString *passESN;
- (void)waitForData:(sessionVerify)compblock;
- (void)waitForFile:(fileExists)compblock;
- (void)waitForESN:(parsingData)compblock;
- (void)findESN:(gettingESNBlock)callback;
- (void)checkThumb:(touchIDSuccess)compblock;
- (void)readIt:(sessionRetrieved)compblock;
- (void)readNewSession:(sessionReading)compblock;
- (void)doTheWork:(NSString *)theESN withSession:(NSString *)newSession withSuccess:(BOOL)success error:(NSError *)error;
- (void)checkESN:(checkingESNBlock)callback;
- (void)checkTheSession:(NSString *)oldESN withSession:(NSString *)oldSession withSuccess:(BOOL)success error:(NSError *)error;
- (void)fillAppointmentData:(fillArray)compblock;
- (void)gettingData:(getTheData)compblock;
@end
Security.m
@implementation Security
void(^getESNForCallback)(NSString *myESN, NSString *newSession, BOOL success, NSError *error);
void(^checkESNWithCallback)(NSString *myESN, NSString *oldSession, BOOL success, NSError *error);
- (void)waitForFile:(fileExists) compblock {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectoryPath stringByAppendingString:@"/session.txt"];
compblock([fileManager fileExistsAtPath:fullPath]);
}
- (void) waitForData:(sessionVerify) compblock {
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:self.request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
return;
}
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if (statusCode != 200) {
if (statusCode == 401) {
// Insert process for thumbprint and session cookie pull
NSFileManager *fileManagerThree = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sessionPath = [documentsPath stringByAppendingPathComponent:@"session.txt"];
NSError *error;
BOOL success = [fileManagerThree removeItemAtPath:sessionPath error:&error];
if (success) {
} else {
}
} else {
return;
}
}
}
self.parseData = data;
compblock (YES);
}];
[task resume];
}
- (void)waitForESN:(parsingData) compblock {
ParseTypeXML *myParser = [[ParseTypeXML alloc] initWithData:self.parseData];
VariableStore *globals = [VariableStore sharedInstance];
if ([myParser.esn count] == 0) {
globals.user_esn = @"Error";
compblock(YES);
} else {
globals.user_esn = myParser.esn[0];
compblock(YES);
}
}
- (void)findESN:(gettingESNBlock)callback {
getESNForCallback = callback;
VariableStore *globals = [VariableStore sharedInstance];
[self doTheWork:globals.user_esn withSession:globals.sessionInfo withSuccess:YES error:nil];
}
- (void)doTheWork:(NSString *)theESN withSession:(NSString *)newSession withSuccess:(BOOL)success error:(NSError *)error {
[self checkThumb:^(BOOL finished) {
if(finished) {
[self readIt:^(BOOL newFile) {
if (newFile) {
[self readNewSession:^(BOOL seen) {
if (seen) {
VariableStore *globals = [VariableStore sharedInstance];
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@"ollie/", NSHTTPCookieDomain,
@"\\", NSHTTPCookiePath,
@"Cookie", NSHTTPCookieName,
globals.sessionInfo, NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
NSArray *cookieArray = [NSArray arrayWithObject:cookie];
NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieArray];
NSMutableString *url = [[NSMutableString alloc] initWithString:@"https://company.com/file.php"];
NSURL *urlNew = [NSURL URLWithString:url];
self.request = [NSMutableURLRequest requestWithURL:urlNew];
[self.request setHTTPMethod:@"GET"];
[self.request setAllHTTPHeaderFields:headers];
[self waitForData:^(BOOL dataReceived) {
if (dataReceived) {
[self waitForESN:^(BOOL esnFound) {
if (esnFound) {
VariableStore *globals = [VariableStore sharedInstance];
getESNForCallback(globals.user_esn, globals.sessionInfo, success, error);
}
}];
}
}];
}
}];
}
}];
}
}];
}
- (void)checkThumb:(touchIDSuccess)compblock {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authenticate User
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@"You need to log in."
reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"success");
compblock(YES);
} else {
switch (error.code) {
case LAErrorAuthenticationFailed:
break;
case LAErrorUserCancel:
break;
case LAErrorUserFallback:
break;
default:
break;
}
}
}];
}
}
- (void)readIt:(sessionRetrieved)compblock {
NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *url = @"https://company.com/specialstring.php";
NSMutableString *postText = [[NSMutableString alloc] init];
[postText appendString:idfv];
NSString *postBody = [NSString stringWithString:postText];
XMLPostSecurity *postAction = [[XMLPostSecurity alloc] init];
VariableStore *globals = [VariableStore sharedInstance];
globals.sessionInfo = [postAction sendPostRequestToUrl:url withBody:postBody];
FileSaving *saver = [[FileSaving alloc] init];
[saver saveSession:globals.sessionInfo];
compblock(YES);
}
-(void)readNewSession:(sessionReading)compblock {
NSFileManager *fileManagerTwo;
NSData *dataBuffer;
fileManagerTwo = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/session.txt"];
dataBuffer = [fileManagerTwo contentsAtPath:filePath];
VariableStore *globals = [VariableStore sharedInstance];
globals.sessionInfo = [[NSString alloc] initWithData:dataBuffer encoding:(NSASCIIStringEncoding)];
compblock(YES);
}
- (void)checkESN:(checkingESNBlock)callback {
checkESNWithCallback = callback;
VariableStore *globals = [VariableStore sharedInstance];
[self checkTheSession:globals.user_esn withSession:globals.sessionInfo withSuccess:YES error:nil];
}
- (void)checkTheSession:(NSString *)theESN withSession:(NSString *)oldSession withSuccess:(BOOL)success error:(NSError *)error {
[self readNewSession:^(BOOL seen) {
if (seen) {
VariableStore *globals = [VariableStore sharedInstance];
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@"ollie/", NSHTTPCookieDomain,
@"\\", NSHTTPCookiePath,
@"Cookie", NSHTTPCookieName,
globals.sessionInfo, NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
NSArray *cookieArray = [NSArray arrayWithObject:cookie];
NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieArray];
NSMutableString *url = [[NSMutableString alloc] initWithString:@"https://company.com/file.php"];
NSURL *urlNew = [NSURL URLWithString:url];
self.request = [NSMutableURLRequest requestWithURL:urlNew];
[self.request setHTTPMethod:@"GET"];
[self.request setAllHTTPHeaderFields:headers];
[self waitForData:^(BOOL dataReceived) {
if (dataReceived) {
[self waitForESN:^(BOOL esnFound) {
if (esnFound) {
VariableStore *globals = [VariableStore sharedInstance];
checkESNWithCallback(globals.user_esn, globals.sessionInfo, success, error);
}
}];
}
}];
}
}];
}
- (void)fillAppointmentData:(fillArray)compblock {
VariableStore *globals = [VariableStore sharedInstance];
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@"ollie/", NSHTTPCookieDomain,
@"\\", NSHTTPCookiePath,
@"Cookie", NSHTTPCookieName,
globals.sessionInfo, NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
NSArray *cookieArray = [NSArray arrayWithObject:cookie];
NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieArray];
NSMutableString *url = [[NSMutableString alloc] initWithString:@"https://company.com/file2.php?adb="];
[url appendString:globals.chosenDate];
[url appendString:@"&esn="];
[url appendString:globals.user_esn];
NSURL *urlNew = [NSURL URLWithString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlNew];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
[self gettingData:^(NSData *myData, NSError *error) {
if (myData != nil) {
ParseXML *myParser = [[ParseXML alloc] initWithData:myData];
[globals.appointmentData removeAllObjects];
[globals.appointmentData addObjectsFromArray:myParser.items];
}
}];
}
- (void) gettingData:(getTheData) compblock {
VariableStore *globals = [VariableStore sharedInstance];
globals.got401 = nil;
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:self.request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
return;
}
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if (statusCode != 200) {
if (statusCode == 401) {
// Insert process for thumbprint and session cookie pull
NSFileManager *fileManagerThree = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sessionPath = [documentsPath stringByAppendingPathComponent:@"session.txt"];
NSError *error;
BOOL success = [fileManagerThree removeItemAtPath:sessionPath error:&error];
if (success) {
} else {
}
globals.got401 = @"Error";
} else {
return;
}
}
}
self.parseData = data;
}];
[task resume];
}
@end
ありがとうございました。私はコードを追加しました。私はどのように進めるのか混乱しているので完全ではありません。以前の質問には次のものが含まれます:http://stackoverflow.com/questions/37467044/enterprise-app-crashes-after-install-from-mdmおよびhttp://stackoverflow.com/questions/37196370/ios-9-making-code- go-sequential-touch-idどんな助けでも大歓迎です。 –