Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Fix for #64 . Increased requirement for ios platform to 4.0.0 or above.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Dec 17, 2015
1 parent f0c620b commit 0e5b29d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ It is also possible to install via repo url directly (__unstable__)
cordova plugin add https://github.com/nordnet/cordova-hot-code-push.git
```

**Note: Be aware, that at the moment github version of the plugin is not compatible with iOS Cordova versions below 4.0.0. So, please install the latest ios cordova platform: `cordova platform add ios@4.0.0`. Same goes for Ionic projects: `ionic platform add ios@4.0.0`.**

At the end of the installation plugin will recommend you to install [Cordova Hot Code Push CLI client](https://github.com/nordnet/cordova-hot-code-push-cli). This client will help you to:
- easily generate necessary configuration files;
- launch local server to listen for any changes in the web project and deploy new version immediately on the app.
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<issue>https://github.com/nordnet/cordova-hot-code-push/issues</issue>

<engines>
<engine name="cordova-ios" version=">=3.8" />
<engine name="cordova-ios" version=">=4" />
<engine name="cordova-android" version=">=4" />
<engine name="cordova-plugman" version=">=4.2.0" /><!-- needed for gradleReference support -->
</engines>
Expand Down
23 changes: 17 additions & 6 deletions src/ios/HCPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @interface HCPPlugin() {
HCPXmlConfig *_pluginXmllConfig;
HCPApplicationConfig *_appConfig;
HCPAppUpdateRequestAlertDialog *_appUpdateRequestDialog;
NSURLRequest *_lastRequest;
}

@end
Expand Down Expand Up @@ -242,21 +243,31 @@ - (BOOL)_installUpdate:(NSString *)callbackID {
*/
- (void)loadURL:(NSURL *)url {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{

NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:cache];

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
NSString *path = components.path;
NSURL *loadURL = [NSURL fileURLWithPath:path];

[[NSURLCache sharedURLCache] removeAllCachedResponses];
[self.webView loadRequest:[NSURLRequest requestWithURL:loadURL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:60.0]];
if (_lastRequest) {
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:_lastRequest];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}

_lastRequest = [NSURLRequest requestWithURL:loadURL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10000];

[self.webViewEngine loadRequest:_lastRequest];

// We need to reload the page because of the webview caching.
// For example, if we loaded new css file - it is not gonna update, bacuse old version is cached and the file path is the same.
// But if we reload page - everything is fine. This is hacky, but it is the only way to reset the cache.
// Delay is set, because if we try to reload immidiatly - nothing good will happen.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.webView reload];
[self.webViewEngine evaluateJavaScript:@"window.location.reload(true);" completionHandler:nil];
});
}];
}
Expand All @@ -265,7 +276,7 @@ - (void)loadURL:(NSURL *)url {
* Redirect user to the index page that is located on the external storage.
*/
- (void)resetIndexPageToExternalStorage {
NSString *currentUrl = self.webView.request.URL.path;
NSString *currentUrl = [self.webViewEngine URL].path;
if ([currentUrl containsString:_filesStructure.wwwFolder.absoluteString]) {
return;
}
Expand Down

0 comments on commit 0e5b29d

Please sign in to comment.