Xcode objective C: How Clean code from UIWebView (ITMS-90809) - objective-c

I use Windev mobile to developpe apps for both Android and IOS. For IOS apps, Windev mobile gave me an objective-c project that i should build in xcode then send to app store ..
I'm know only basics of basics step on xcode and i need to clean my code from "UIWebView", I have seen more than discussion about that but none of them repond to my case ..
For exemple thay talk about using: grep -r UIWebView project path .
But i realy dont know how to use that ...
Please your help will be very very appreciated !
Thanks!

Really just some guidance - how to do it actually depends on your situation.
Don't use grep - just use your IDE's search to locate all the UIWebView and then replace them with WKWebView. It can be as simple as that depending on what you use your webview's for. If for complex processing then you'll need to figure out how to do what you did in UIWebView in the WKWebView.
Another suggestion - why not wrap all your UIWebViews in some custom class and move all the functionality in there. Then it is easy to replace the UIWebView there and also rework the functionality there with the class staying the same. Apart from the functionality you'll have code that looks something like this in there.
+ ( UIWebView / WKWebView * ) addWebViewToView:( UIView * ) view
{
// Code to create webview - initially UIWebView and later WKWevView
..
// Code to embed the webview into the view
.. set the constraints to fill the view
return webview;
}
Then you can use normal UIView's in your project and use this to prime them with a webview.
To this you can later add navigation delegates to beef up the functionality or, if you just use the webview to display some HTML, you can pass in the string or URL to display.

Related

Titanium - Reset zoom scale in webview

Is it possible to programmatically reset the zoom/scale that the user has done in a webview? My issue is when the webview is pinch zoomed in landscape and you rotate the phone, the webview is still zoomed in and in my case, portrait mode is now extremely zoomed in.
I've tried webview.repaint() but that seems to do absolutely nothing. I know I can call webiew.reload() but that just uses more bandwidth for my server as well as the users data plan so I want to avoid that.
I'm using Titanium Studio, build: 3.1.3.xxx, 3.1.3 GA Ti SDK and compiling for iOS 7 SDK.
Based on this thread and the fact that there was no way to easily achieve this, I have created a module. It extends the Ti.UI.WebView with two methods, setZoomLevel() and scrollToTop(). It is very basic at the moment, but I'm planning on extending its functionality gradually.
https://github.com/mwfire/titanium-module-extended-webview
Have a look, it's an alternative to modifying the core code.
Did you give a try at setting the scalesPageToFit property of your webview upon orientation change?
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.WebView-property-scalesPageToFit
I found the answer which was a bit more than I wanted to do. I had to actually modify the Titanium SDK obj-c files.
I modified 3 files:
TiUIWebView.h
-(void)resetZoomScale; //-- added this line to define the function in the header file
TiUIWebView.m
//-- Added this function that will actually handle the resize
- (void)resetZoomScale
{
[webview.scrollView setZoomScale:1.0]; //-- reset the scroll view back to 1
}
TiUIWebViewProxy.m
//-- Call the resetZoomScale function in TiUIWebView.m file
//-- I believe this also exposes the function to javascript
-(void)resetZoomScale:()args
{
TiThreadPerformOnMainThread(^{[(TiUIWebView*)[self view] resetZoomScale];}, NO);
}
I can now call myWebView.resetZoomScale(); and whatever pinch/zooming has been done on the web view will be reset back none or 1

Cannot find protocol declaration for 'UIWebViewDelegate'

I am trying to utilize UIWebView functionality, specifically I want to do something like this: Open links in Safari instead of UIWebVIew?
But I am having an issue when I try and add the UIWebViewDelegate to my AppDelegate interface.
Anyone know what the issue is? Note this is Mac OS not iOS.
Add:
#import <UIKit/UIKit.h>
Anyone know what the issue is? Note this is Mac OS not iOS.
That's the issue right there.
There is no UIWebView or UIWebViewDelegate on MacOS X. UI is the prefix for UIKit, which is the iOS equivalent of AppKit. When you see a class whose name begins with UI, you know immediately that you're looking at iOS code.
The class you're probably looking for is WebView. WebView actually uses five separate delegates, so you may need to implement as many as five different protocols: WebUIDelegate, WebDownload, WebFrameLoadDelegate, WebPolicyDelegate, and WebResourceLoadDelegate. (In reality, I don't think you need to do quite that much work. For example, you may not need to implement your own access policy.)
UIWebView is iOS only. You cannot use a UIWebViewDelegate for Mac OSX. If you look at your own code, you are using a WebView, not a UIWebView.
You'll want to look at the WebView class docs

iOS 5 - Camera Overlay Clone

Is there an open source nib out that that's a clone of the overlay view that Apple uses for its Camera.app? I'm currently using UIImagePickerController with picker.showCameraControls = YES, but I need to tweak the functionality ever so slightly.
I've been thinking of subclassing the UIImagePickerController, but would that give me more control over takePicture? Specifically, I want to be able to call that method without forcing the user to leave the interface.
This is what the AVCaptureSession class is for. The documentation shows how to set up a captureSession, from there it's all cake!

iOS - Asynchronous Image Downloading

I am writing an app which is going to be displaying images found on my server in a UIImageView.
I need something that will asynchronously download the image and cache it while putting it in the UIImageView.
The download also needs to be able to be cancelled when I press a button.
Can anyone point me in the direction of something that can do this?
In the old times the framework for that was ASIHTTPRequest but is an abandoned project now. This https://github.com/AFNetworking/AFNetworking seems to be popular now.
Use the performSelectorInBackground:withObject: - method from NSObject ;)
Advise: The updating of the view must run on the main thread!
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html

How do I use a RootViewController when making an app without a ViewController?

I am trying to make a simple app from a tutorial that does not have a viewController at all. All the code is in the AppDelegate. I am on xcode 4.2 and I am getting this error:
Applications are expected to have a root view controller at the end of application launch
I'm not sure how to deal with this. There are some blogs out there with fixes but none of them are working for me and I really would like to understand what is going on here. And, how to fix it.
I do have a view that contains some buttons and labels. But I have no "ViewController". The files contained in my project are: AppDelegate.h, AppDelegate.m, and Window.xib only. There is no ViewController.h, ViewController.m
** edit **
I ended up making the app from a 'view based application' instead and just moving all the logic from the app delegate to the view controller. So, I didn't really solve the problem per se. The app works now though. Thanks for the help
It's not possible to have an iOS app that doesn't have a view controller. You can always create a trivial view controller, i.e.,
[[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds].rootViewController =
[[[UIViewController alloc] init] autorelease];
It sounds like you're looking at an old tutorial. UIWindow got a rooViewController property in iOS4. I believe it became required in iOS5 to help keep controller hierarchies and view hierarchies in sync with the addition of custom container controllers (and to fix a corner case where replacing the "root controller" of a UIWindow could stop orientation changes from propagating). There was a WWDC presentation in 2011 that explained this in some detail. I think it was Session 102, Implementing UIViewController Containment.
At then end of the day, there's no good reason not to have a root view controller. Apple wants to be able to assume it's there in their APIs going forward. If the tutorial you're looking at doesn't account for that, it's broken.
While I agree that there may be workarounds, another question to address is: why do you want an app without a view? Even if it's designed to run in the background and present no visual interface, at least make a simple view showing the application name and version, a largeish icon and perhaps a status. This kind of idle screen uses very little system resources, especially when the app is backgrounded, but improves the overall experience of the app.
If you set your deployment target to 4.3 and run on the iPhone 4.3 simulator, you won't get the warning.
To install the iOS 4.3 simulator, go to Xcode > Preferences > Downloads.