Developing the Native App for ipad,
Initial screen i have on 'ViewDidLoad' a webcall made to read a file on web getting me the results and showing the list.
Prob 1: when i change the content of file in Web it doesnt reflect in my app, even i kill app still result is old same. can anyone help me with this issue.
After this list select it lands to WebView.
Prob 2: When i change anything on server side javascript. it doesnt reflect on the Native App, it does still give me old response only. (i.e Javascript and Css changes are not reflect in App). Can anyone please help me throught this part.
IOS 7 native App in Ipad. If you need code i can post it.
You should specify a CachePolicy:
enum
{
NSURLRequestUseProtocolCachePolicy = 0,
NSURLRequestReloadIgnoringLocalCacheData = 1,
NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
NSURLRequestReturnCacheDataElseLoad = 2,
NSURLRequestReturnCacheDataDontLoad = 3,
NSURLRequestReloadRevalidatingCacheData = 5, // Unimplemented
};
typedef NSUInteger NSURLRequestCachePolicy;
Try this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:myURLString] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:nil]];
Related
We are trying to migrate a hybrid app from UIWebView (iOS < 8) to WKWebView (iOS 8), but we are getting SecurityErrors when trying to store stuff using the DOM WebDatabase API (i.e. 'web sql databases').
The following throws an error if the index.html has been loaded from a bundled file with the app
// throws SecurityError: DOM Exception 18
var db = openDatabase('mydb', '1.0', 'key value store', 1);
The same code works fine with UIWebView. I can fallback to using Local Storage for some reason, but using WebSQL databases is a no go. I can only speculate that this has something to do with the same origin policy or something related.
The funny thing is that loading index.html from the network works fine :-/
Any clues as to how I can work around this? Any options to set on the WKWebView that fixes it?
This is how we load the web related stuff:
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
[config.userContentController addScriptMessageHandler:self.myCallbacks name:#"NativeApp"];
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:config];
[self.webView loadRequest:request];
The html file simply loads a javascript file that has a relative path, "myCode.js".
There is an issue (OpenRadar) with WKWebView in iOS 8.0 (and 8.1 B1, I think) that prevents it from loading local files. It might be affecting local storage too. See this question for more details.
You can fix this by adding the following method to the UIDelegate of your WKWebView.
- (void) _webView:(WKWebView *)webView
decideDatabaseQuotaForSecurityOrigin:(WKSecurityOrigin *)securityOrigin
currentQuota:(unsigned long long)currentQuota
currentOriginUsage:(unsigned long long)currentOriginUsage
currentDatabaseUsage:(unsigned long long)currentUsage
expectedUsage:(unsigned long long)expectedUsage
decisionHandler:(void (^)(unsigned long long newQuota))decisionHandler {
decisionHandler(1024*1024*50); //default to 50MB
}
It gives all databases a quota of 50MB, instead of the default of 0 which allows them to be opened. This behavior isn't documented, so I don't know where Apple stands with this.
Also, it appears this issue will be fixed in iOS 10.
I've made a 'plugin' that allows you to use WebSQL (more an implementation of it) in the WKWebView. It can be found here
https://github.com/ajwhiteway/WKWebSQL
import WKWebSQL
.
.
.
var webView = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration())
WKWebSQL.LoadPlugin(webView)
To get it loaded into the page. Versioning isn't really supported at this time. Feel free to add it.
I use remote url for contents in my cordova, I use appcache to make it work offline - now the problem is handling the initial load before the appcache gets initialized.
In Android I let the device fallback to the local index.html - this could be informative eg. letting the user know that they have to be online to finalize the install.
// On error show default message page...
public void onReceivedError( int errorCode, String description, String failingUrl)
{
super.loadUrl("file:///android_asset/www/index.html");
return;
}
Question: "How do I accomplish the same in IOS?"
Dont have to write the code for me - hints to files and api would be appreciated
You can you the UIWebViewDelegate methods to detect that your remote content loading has failed to load. For example :
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// here you can either check for the error type or for the url that has failed to load
if([webView.request.url.absoluteString isEqualToString:#"your_remote_url")]
{
NSURL *url = [NSURL urlWithString:#"your_local_url"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
}
Since you simply want to do some error handling, one solution to this would be to do a SubView, and load it from whatever URL you need it from.
You can find a guide on how to do this, here:
http://docs.phonegap.com/en/3.0.0/guide_platforms_ios_webview.md.html#iOS%20WebViews
Of course, this gets called from the native part :)
Hope that helped!
I have a UIDocumentInteractionController instance (that DOES have a strong reference in my class, I am aware of the memory issues about it) and I want to send a photo file to Instagram.
I saved the file using the ig extension (tried igo as well) and I am presenting the controller. Instagram is displayed on the list. I tap Instagram, and nothing happens.
NSURL *imageFile = [NSURL fileURLWithPath:path];
interactionController = [UIDocumentInteractionController interactionControllerWithURL:imageFile];
interactionController.UTI = #"com.instagram.photo";
interactionController.annotation = [NSDictionary dictionaryWithObject:#"my caption" forKey:#"InstagramCaption"];
interactionController.delegate = self;
[interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
To investigate further, I've set my calling class as a delegate and implemented the willBeginSendingToApplication: and didEndSendingToApplication: methods. Interestingly, I've realized that willBeginSendingToApplication: does get called, but didEndSendingToApplication: does not. I've tried changing my file extensions, changing UTI to com.instagram.exclusivegram, checking if the file URL is correct etc. but none of them seem to work. No error, nothing in the console or anything. The interaction controller closes, my app keeps working as it was working before, just nothing happens. I've read that there can be some issues on iOS 6, but my app is an iOS 6 app, so I can't test it on iOS < 6. The only thing that is close to my problem that I've found is UIDocumentInteractionController, No File Extension but UTI but it dives too much into the low level bits, nor I have a non-ARC code.
What could be the cause of the problem?
This can happen if the file doesn't exist, but also if you haven't constructed the file URL correctly. This plagued me for a while.
Make sure you construct your file URL like this:
NSURL *pagesURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"MyGreatPDF.pdf" ofType:nil]];
and not like this:
NSURL *pagesURL = [NSURL fileURLWithPath:#"MyGreatPDF.pdf"];
The latter still forms a valid URL, but it gets a "private" prefix, i.e. file:///private/var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf rather than file:///var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf
After a long while, I've found out that the file was not saved correctly, and didn't exist. iOS wasn't throwing out any sort of an error, failing silently. I've corrected the code about generating the file, and when the file was there, the controller appeared. Maybe Apple should add some assertion/exception mechanism for handling non-existent files in document interaction controller.
This may also caused by the file name's extension.
If the target app declare it only support file with png extension in Info.plist -> Exported Type UTIs -> Equivalent Types -> public.filename-extension, and you send a file with jpg extension, the target app won't open as well.
I'm hosting UIWebView in my app. it looks like UIWebView caches images and data itself.
I want to clear its cache on app startup.
Cleaning up Safari's cache doesn't help. the only way I found to flush UIWebView's cache is to power off my iPhone and turn it again. Closing the app doesn't help either.
Apple documentation says nothing about it...or I'm missing something. Just in case, app is created with monotouch.
If you want to obliterate all cached responses, something like this looks like the way to go:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
There is a view cache that shows a bitmap of the last page used (like we see inside Safari) but that does not looks like what you're seeing (since it requires to reboot the device).
I've not noticed this behaviour before (never looked for it either ;-) but the following answer looks promising.
FWIW this is not something that would be specific to MonoTouch.
Ive tried all the suggestions on stack overflow and none of them work. The only way I got it to work and feel that its a reliable solution is to create new html files on a temp directory (with a different directory name - a Guid works best) every time, and copy all the related images, scripts, css, every time to that temp directory.
Then open it using an NSUrlRequest object
string tempdir = Path.Combine(UIController.Common.DataFolder,System.Guid.NewGuid().ToString ());
Directory.CreateDirectory (tempdir);
//-- create your html on the tempdirectory here
//-- copy all the images, and all the css, and js files
UIWebView wv = new UIWebView(new RectangleF(30,30,480,680));
NSUrlRequest req = new NSUrlRequest(new NSUrl (Path.Combine (tempdir,"default.html"), false),NSUrlRequestCachePolicy.ReloadRevalidatingCacheData,10);
wv.LoadFinished += delegate(object sender1, EventArgs e1)
{
//delete the tempdirectory
Directory.Delete(tempdir);
};
It seems that over the weekend, the following Delegate method
- (void)OAuthTwitterController:(SA_OAuthTwitterController *)controller authenticatedWithUsername:(NSString *)username
began returning nil for the username parameter.
I wanted to see if anyone else using Ben Gottlieb's SDK can confirm this issue.
Thanks
I had the same issue today. The app worked fine for the past 2 months.
One thing I changed was the bundle id. Maybe this has something to do with this error, because everything else is the same. Did you happen to change this too?
I changed to https the urls for twitter on SA_OAuthTwitterEngine.m and it seems to be working fine now.
Here is the code I changed:
self.requestTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://twitter.com/oauth/authorize"];
This still works fine for me. Have you tried the native Twitter API (if that's an option)?