从MDM安装后,企业应用程序崩溃 [英] Enterprise App Crashes after Install from MDM

查看:89
本文介绍了从MDM安装后,企业应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个iOS 9.2应用程序,当通过Xcode和本地Mac安装时,可以在测试中正常运行.当我们通过MDM服务器安装此应用程序时,它在首次访问数据时崩溃.正在退出,并显示错误"10.00秒后无法更新场景".

We have an iOS 9.2 app that runs fine in testing when installed via Xcode and the local Mac. When we install this application through our MDM server it crashes on the first access of data. It is exiting with the error "failed to scene-update after 10.00s."

我从检查控制台输出来看,它似乎在requireLogin方法中的成功过程之后挂起(在[self checkIntSession:self.sessionDetail]之后.

I from checking the console output, it appears to be hanging up after the success process in the requireLogin method (after the [self checkIntSession:self.sessionDetail].

我们正在使用Novell的MDM而不是Apple版本.我创建了其他已安装并运行正常的应用程序.

We are using Novell's MDM not the Apple version. I have created other applications that have installed and run with no problems.

我尝试了一个全新的构建和安装.它没有帮助.我找不到在这里或其他任何地方回答的类似问题.我不知道接下来要去哪里.任何帮助将不胜感激.

I have tried a clean build and install. It did not help. I cannot find an similar question answered here or anywhere else. I'm at a loss for where to go with this next. Any help would be appreciated.

#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调用的:

It is called from ViewController.m:

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

===稍后添加===

=== Later Add ===

放入完成块并不能解决问题.完成requireLogin成功部分后,该代码似乎仍然挂起.就像我需要退货之类的东西.

Putting in the completion blocks has not resolved the problem. The code still seems to hang after completing the requireLogin success section. Like I need a return or something.

推荐答案

这行对我来说太可怕了:

This line looks super scary to me:

  while ( self.parseData == NULL );

这可能是调试版本与发行版本之间的问题.我可以想象一个发布版本可以优化self.parseData的读取,而不必继续检查其他线程是否已对其进行更新.

It might be a debug vs. release build issue. I could imagine a release version optimizing the read of self.parseData to not keep checking if other threads have updated it.

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

I recommend that you do this some other way -- polling in a loop like this pegs the CPU at 100% while it's waiting. I would suggest writing it to be asynchronous with completion blocks that you call when the data is ready.

这篇关于从MDM安装后,企业应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆