gpt4 book ai didi

ios - 从 MDM 安装后企业应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 11:59:46 25 4
gpt4 key购买 nike

我们有一个 iOS 9.2 应用程序,当通过 Xcode 和本地 Mac 安装时,它在测试中运行良好。当我们通过 MDM 服务器安装此应用程序时,它会在第一次访问数据时崩溃。它正在退出并出现错误“10.00 秒后场景更新失败。”

我检查控制台输出,它似乎在 requireLogin 方法成功处理后挂断(在 [self checkIntSession:self.sessionDetail] 之后)。

我们使用的是 Novell 的 MDM 而不是 Apple 版本。我已经创建了其他安装和运行没有问题的应用程序。

我尝试了干净的构建和安装。它没有帮助。我找不到在这里或其他任何地方回答的类似问题。我不知道下一步该去哪里。任何帮助将不胜感激。

#import "Security.h"
#import "XMLTypeItem.h"
#import "ParseTypeXML.h"
#import "XMLPostSecurity.h"
#import "XMLSessionItem.h"
#import "FileSaving.h"
#import <LocalAuthentication/LocalAuthentication.h>

@implementation Security

- (NSString *)retrieveESN {

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectoryPath stringByAppendingString:@"/session.txt"];
if ([fileManager fileExistsAtPath:fullPath]==YES) {
_finished = false;
[self readSession];
NSString *result = [self checkSession:_sessionDetail];
if ([result isEqualToString:@"Error"]) {
NSString *userESN = [self newFile];


if (self.getUserESN){
self.getUserESN(userESN);
}

return userESN;
} else {
return result;
}
} else {
_finished = false;
NSString *userESN = [self newFile];
return userESN;
}
}

- (NSString *)newFile {
[self requireLogin];

if (self.findUserESN) {
self.findUserESN(_passESN);
}

return _passESN;
}


- (void)requestSession {
NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *url = @"https://company.com/loginfile";

NSMutableString *postText = [[NSMutableString alloc] init];

[postText appendString:idfv];

NSString *postBody = [NSString stringWithString:postText];

XMLPostSecurity *postAction = [[XMLPostSecurity alloc] init];
_sessionDetail = [postAction sendPostRequestToUrl:url withBody:postBody];

FileSaving *saver = [[FileSaving alloc] init];

[saver saveSession:self.sessionDetail];
}

-(NSString *)readSession {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectoryPath stringByAppendingString:@"/session.txt"];

if (self.fileExistsNow) {
self.fileExistsNow([fileManager fileExistsAtPath:fullPath]);
}

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];
_sessionDetail = [[NSString alloc] initWithData:dataBuffer encoding:(NSASCIIStringEncoding)];

return _sessionDetail;
}

-(void)readIntSession {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectoryPath stringByAppendingString:@"/session.txt"];

if (self.fileExistsNow) {
self.fileExistsNow([fileManager fileExistsAtPath:fullPath]);
}

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];
_sessionDetail = [[NSString alloc] initWithData:dataBuffer encoding:(NSASCIIStringEncoding)];
}

-(NSString *)checkSession:(NSString *)sessionFound {
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@"ollie/", NSHTTPCookieDomain,
@"\\", NSHTTPCookiePath,
@"Cookie", NSHTTPCookieName,
sessionFound, 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];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlNew];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest: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;
}];
[task resume];

if (self.parseDataAvailable) {
self.parseDataAvailable(self.parseData);
}

ParseTypeXML *myParser = [[ParseTypeXML alloc] initWithData:self.parseData];
if ([myParser.esn count] == 0) {
return @"Error";
} else {
return myParser.esn[0];
}
}

-(void)checkIntSession:(NSString *)sessionFound {
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@"ollie/", NSHTTPCookieDomain,
@"\\", NSHTTPCookiePath,
@"Cookie", NSHTTPCookieName,
sessionFound, 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];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlNew];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest: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;
}];
[task resume];

if ( self.parseDataAvailable) {
self.parseDataAvailable(self.parseData);
}

ParseTypeXML *myParser = [[ParseTypeXML alloc] initWithData:self.parseData];
if ([myParser.esn count] == 0) {
_passESN = @"Error";
} else {
_passESN = myParser.esn[0];
}
}

- (void)requireLogin {

LAContext *context = [[LAContext alloc] init];
NSError *error = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authenticate User
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@"You must log in to the app."
reply:^(BOOL success, NSError * _Nullable error) {

if (success) {
self.finished = true;
if (self.touchIDWorks){
self.touchIDWorks(self.finished);
}
[self requestSession];
[self readIntSession];
[self checkIntSession:self.sessionDetail];
} else {
switch (error.code) {
case LAErrorAuthenticationFailed:
break;
case LAErrorUserCancel:
break;
case LAErrorUserFallback:
break;

default:
break;
}
}
}];
} else {
}
}

- (void)dataIsThere:(void (^)(NSData *foundData))finishBlock {
self.parseDataAvailable = finishBlock;
}

- (void)thumbOK:(void (^)(BOOL success))finishBlock {
self.touchIDWorks = finishBlock;
}

- (void)esnIsHere:(void (^)(NSString *newESN))finishBlock {
self.getUserESN = finishBlock;
}

- (void)esnIsReady:(void (^)(NSString *))finishBlock {
self.findUserESN = finishBlock;
}

- (void)fileReady:(void (^)(BOOL))finishBlock {
self.fileExistsNow = finishBlock;
}

它是从 ViewController.m 中调用的:

- (IBAction)getESN:(id)sender {
Security *pulledESN = [[Security alloc] init];
self.gottenESN = [pulledESN retrieveESN];
self.responseLabel.text = self.gottenESN;
}

=== 稍后添加 ===

放入完成 block 并没有解决问题。在完成 requireLogin 成功部分后,代码似乎仍然挂起。就像我需要返回什么的。

最佳答案

这条线对我来说 super 可怕:

  while ( self.parseData == NULL );

这可能是调试与发布构建问题。我可以想象一个发布版本优化了 self.parseData 的读取,而不是继续检查其他线程是否更新了它。

我建议您以其他方式执行此操作——在这样的循环中轮询,在等待时将 CPU 固定在 100%。我建议将其编写为与您在数据准备就绪时调用的完成 block 异步。

关于ios - 从 MDM 安装后企业应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37467044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com