diff --git a/LiquidCore/src/ios/API/LCMicroService.m b/LiquidCore/src/ios/API/LCMicroService.m index 1f6635fa87..8fca999bb5 100644 --- a/LiquidCore/src/ios/API/LCMicroService.m +++ b/LiquidCore/src/ios/API/LCMicroService.m @@ -40,11 +40,14 @@ + (id) serviceFromInstanceId:(NSString*)instanceId + (void) uninstall:(NSURL *)serviceURI { NSString *serviceId; - NSRange comp = [[serviceURI absoluteString] rangeOfString:@"/" options:NSBackwardsSearch]; + NSString *serviceString = [serviceURI absoluteString]; + NSString *bundleString = NSBundle.mainBundle.bundleURL.absoluteString; + serviceString = [serviceString stringByReplacingOccurrencesOfString:bundleString withString:@""]; + NSRange comp = [serviceString rangeOfString:@"/" options:NSBackwardsSearch]; if (comp.location != NSNotFound) { - serviceId = [[serviceURI absoluteString] substringToIndex:comp.location]; + serviceId = [serviceString substringToIndex:comp.location]; } else { - serviceId = [serviceURI absoluteString]; + serviceId = serviceString; } serviceId = [serviceId stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLHostAllowedCharacterSet]]; @@ -146,12 +149,15 @@ - (id) initWithURL:(NSURL*)serviceURI delegate:(id)deleg self = [super init]; if (self) { _serviceURI = serviceURI; - NSRange comp = [[serviceURI absoluteString] rangeOfString:@"/" options:NSBackwardsSearch]; + NSString *serviceString = [serviceURI absoluteString]; + NSString *bundleString = NSBundle.mainBundle.bundleURL.absoluteString; + serviceString = [serviceString stringByReplacingOccurrencesOfString:bundleString withString:@""]; + NSRange comp = [serviceString rangeOfString:@"/" options:NSBackwardsSearch]; if (comp.location != NSNotFound) { - serviceId_ = [[serviceURI absoluteString] substringToIndex:comp.location]; - module_ = [[serviceURI absoluteString] substringFromIndex:comp.location+1]; + serviceId_ = [serviceString substringToIndex:comp.location]; + module_ = [serviceString substringFromIndex:comp.location+1]; } else { - serviceId_ = [serviceURI absoluteString]; + serviceId_ = serviceString; module_ = serviceId_; } comp = [module_ rangeOfString:@"?"]; @@ -187,12 +193,8 @@ - (NSError*) fetchService if ([self.serviceURI isFileURL]) { // Symlink file for speed - if ([fileManager fileExistsAtPath:localPath]) { - [fileManager removeItemAtPath:localPath error:&error]; - } - if (error == nil) { - [fileManager createSymbolicLinkAtURL:[NSURL fileURLWithPath:localPath] withDestinationURL:self.serviceURI error:&error]; - } + [fileManager removeItemAtPath:localPath error:nil]; + [fileManager createSymbolicLinkAtURL:[NSURL fileURLWithPath:localPath] withDestinationURL:self.serviceURI error:&error]; self.fetched = true; } else { NSDate* lastModified = nil; @@ -231,9 +233,7 @@ - (NSError*) fetchService NSHTTPURLResponse *http = (NSHTTPURLResponse*)response; error = e; if (error == nil && http.statusCode == 200) { - if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) { - [[NSFileManager defaultManager] removeItemAtPath:localPath error:nil]; - } + [[NSFileManager defaultManager] removeItemAtPath:localPath error:nil]; [[NSFileManager defaultManager] moveItemAtURL:location toURL:[NSURL fileURLWithPath:localPath] error:nil]; @@ -247,14 +247,10 @@ - (NSError*) fetchService NSBundle *bundle = [NSBundle mainBundle]; NSURL *bundleURL = [[bundle resourceURL] URLByAppendingPathComponent:@"LiquidCore.bundle"]; NSURL *fileURL = [NSBundle URLForResource:bundleName withExtension:@"js" subdirectory:nil inBundleWithURL:bundleURL]; - if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) { - [[NSFileManager defaultManager] removeItemAtPath:localPath error:&error]; - } - if (error == nil) { - [[NSFileManager defaultManager] copyItemAtURL:fileURL - toURL:[NSURL fileURLWithPath:localPath] - error:&error]; - } + [[NSFileManager defaultManager] removeItemAtPath:localPath error:nil]; + [[NSFileManager defaultManager] copyItemAtURL:fileURL + toURL:[NSURL fileURLWithPath:localPath] + error:&error]; if (error == nil) { self.fetched = true; return;