Sunday, December 28, 2014

iOS8 UIWebView

iOS8..   Horrible when it comes to lockscreens. Why? Well Apple is now pushing a different webview.

Which is good for people who get to use the new WKWebView, but most of us are stuck with the old webview. Case in point Cydget. Cydget still uses UIWebView. When I asked Saurik if he planned on updating to the new WebView he explained a few points on why that wouldn't be a good idea. After doing some research, I would rather keep the UIWebView we have for the time being. The new WKWebView has bugs, as does most new implementations. It kills javascript timers and the ability to read local files. Two big things when it comes to lockscreens. Although it does run sooo much "leaner" than UIWebView I feel it isn't ready yet.

My theory is since Apple is moving forward with WKWebView they are not giving UIWebView as many resources as it once had. This leads to performance issues when we use this UIWebView. By running quite a bit of javascript you may see lockscreen cause a respring. This is iOS8's way of clearing this memory. So how do we work with the old UIWebView on iOS8?

Well we remove stuff.

First thing I decided to tackle was the lockscreen background. This image is quite large, just think of the size of a 6+ device. Since most lockscreens just cover up the settings set wallpaper (yes its always there) why not just change the settings set wallpaper?

Now this can only be done in Cydget as it has the ability to use Cycript, so this is mainly for people who use cydget.

Here is how I was able to take a wallpaper and set it as the settings set wallpaper.

setWeatherWall = function(url){
img=[UIImage imageWithContentsOfFile:@""+url];
wViewController = [[[PLStaticWallpaperImageViewController alloc] initWithUIImage:img] autorelease];
wViewController->_wallpaperMode=2;
wViewController.saveWallpaperData = YES;
[wViewController _savePhoto];
}

I just created a function with a url as a parameter. I would then use this function where I pulled my weather info. Basically setting a weather wallpaper, but instead of displaying the wallpaper in the html, I just sent the url of the wallpaper being used to this function and it would set it to the stock wallpaper.

Example of what I would have in my weather code. currentIcon would be the current condition.
var newimage="var/mobile/Library/LBEvoWeatherWalls/Icons/"+currentIcon+".jpg";
setWeatherWall(newimage);

So what does this function do?

img=[UIImage imageWithContentsOfFile:@""+url];
takes the image and converts it to a UIImage

wViewController = [[[PLStaticWallpaperImageViewController alloc] initWithUIImage:img] autorelease];
creates a view controller. Think of this like the window you see when you go to settings/wallpaper and set a wallpaper.

wViewController->_wallpaperMode=2;
sets the wallpaper mode to 2. This will set the wall to the lockscreen instead of springboard. for springboard set to 1. (thanks to kirbylover for the help with this)

wViewController.saveWallpaperData = YES;
set to YES to save wallpaper data

[wViewController _savePhoto];
set the photo to lockscreen. basically this would be when you press set lockscreen.

Doesn't that seem like the right thing to do? I sure do, and wish more people would open their eyes and add Cycript ability to their lockscreen platforms (GroovyLock, LockHTML4 etc).

You now have your weather wallpaper set to the lockscreen, and you didn't have to load it in your html at all, also it will fit all devices.

Next up would be handling blurs. Since you no longer have a wallpaper in your html, you can no longer blur it with say -webkit-transform:blur(); which is good as it really eats up resources. I achieved a blur using the code below. This blurs the lockscreen wallpaper, much like when a notification comes it.

 [[[[SBLockScreenManager sharedInstance]lockScreenViewController]lockScreenView]_showFakeWallpaperBlurWithAlpha:1 withFactory:null];

 _showFakeWallpaperBlurWithAlpha: can be from 0 to 1. You can set a float such as 0.5, 0.2 etc. This will change the amount of blur added. 1 being the highest and 0 being no blur at all. This will blur any wallpaper set to settings. You can see the effect in the video below. When the lockscreen is scrolled it applies the blur, when it is set back to top it will unblur it.

http://t.co/2humzGBsUP






No comments:

Post a Comment