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






Sunday, February 16, 2014

Using a preference bundle in cydget

Recently I found this Reddit post from looking at Saurik's reddit It further explained how to use preferenceloader to load plist entries. After fiddling around a bit, I was able to add this to miWeather Cydget



It implemented very easily, a lot easier than you would think. Now I don't see how we went so long without adding this to Cydget Lockscreens. So I have recorded me creating one, to maybe help some understand the procedure. 





Included in the description is the complete files.


Links:
http://iphonedevwiki.net/index.php/PreferenceLoader
http://modmyi.com/forums/file-mods/22453-how-make-custom-menus-preferences-app-custom-preferences.html


Written instuctions

PreferenceLoader includes a few files.

The plist. This can be named however you see fit.
The icon. Can also be named however you like.

The Plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

This is your plist in its lowest form. To add options to the plist we will enter them in between <dict></dict>

For example we want to call our icon.
With this entered in between <dict></dict> it will tell our plist its icon.

<key>entry</key>
<dict>
<key>cell</key>
<string>PSLinkCell</string>
<key>icon</key>
<string>Demo@2x.png</string>
<key>label</key>
<string>Demo</string>
</dict>


Give it a title
<key>title</key>
<string>Demo</string>

Make items in your plist
<key>items</key>
<array>
       </array>

Inside the <arrary></array> we can enter separate <dict></dict> tags to contain certain items. Toggles, Text Entry and more.

<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Demo</string>
</dict>

Above will give you a cell name.
Then under it we can apply different cell items.

              <dict>
<key>cell</key> //What it is
<string>PSEditTextCell</string> //What type of cell
<key>default</key>
<string></string>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string> //plist it will save to
<key>key</key>   //depicts a key
<string>sCityCodes</string>  //name of our key
<key>label</key> // label for this key
<string>Zip Code/Weather Code</string>
<key>placeholder</key>  //what will show when cell is blank
<string>Enter Zip Code/Weather Code</string>
</dict>

There are multiple cell types.

  • PSEditTextCell //shown above
  • PSLinkListCell //lets you choose from a list of items
  • PSSwitchCell // on/off switch (shows true or false)
  • More i'm unaware of at this point


Complete Plist for miWeather
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>entry</key>
<dict>
<key>cell</key>
<string>PSLinkCell</string>
<key>icon</key>
<string>miWeatherPrefs@2x.png</string>
<key>label</key>
<string>miWeather LockScreen</string>
</dict>
<key>items</key>
<array>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Weather</string>
</dict>

        <dict>
<key>cell</key>
<string>PSEditTextCell</string>
<key>default</key>
<string></string>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>key</key>
<string>sCityCodes</string>
<key>label</key>
<string>Zip Code/Weather Code</string>
<key>placeholder</key>
<string>Enter Zip Code/Weather Code</string>
</dict>
    <dict>
<key>cell</key>
<string>PSGroupCell</string>
</dict>
<dict>
<key>cell</key>
<string>PSLinkListCell</string>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>detail</key>
<string>PSListItemsController</string>
<key>key</key>
<string>options</string>
<key>label</key>
<string>Options</string>
<key>validTitles</key>
<array>
<string>0</string>
<string>1</string>
<string>2</string>
</array>
<key>validValues</key>
<array>
<string>0</string>
<string>1</string>
<string>2</string>
</array>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>key</key>
<string>sUnit</string>
<key>label</key>
<string>Turn on for celsius</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>key</key>
<string>TwentyFourHourClock</string>
<key>label</key>
<string>Turn on for 24hr</string>
</dict>

<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>System/Library/LockCydget/miWeather</string>
</dict>

<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>key</key>
<string>userwall</string>
<key>label</key>
<string>User Wall</string>
</dict>

<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Radar</string>
</dict>

<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.JunesiPhone.miWeather</string>
<key>key</key>
<string>world</string>
<key>label</key>
<string>Turn on for outside US</string>
</dict>

<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>miWeather by JunesiPhone
http://JunesiPhone.com</string>
</dict>

</array>
<key>title</key>
<string>miWeather</string>
</dict>
</plist>


Complete Plist for the demo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>entry</key>
<dict>
<key>cell</key>
<string>PSLinkCell</string>
<key>icon</key>
<string>Demo@2x.png</string>
<key>label</key>
<string>Demo</string>
</dict>
<key>items</key>
<array>

 <dict>
<key>cell</key>
<string>PSGroupCell</string>
</dict>
<dict>
<key>cell</key>
<string>PSLinkListCell</string>
<key>defaults</key>
<string>com.JunesiPhone.demo</string>
<key>detail</key>
<string>PSListItemsController</string>
<key>key</key>
<string>options</string>
<key>label</key>
<string>Wallpaper Choices</string>
<key>validTitles</key>
<array>
<string>0</string>
<string>1</string>
<string>2</string>
</array>
<key>validValues</key>
<array>
<string>0</string>
<string>1</string>
<string>2</string>
</array>
</dict>


<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>Demo by JunesiPhone
http://JunesiPhone.com</string>
</dict>

</array>
<key>title</key>
<string>Demo</string>
</dict>
</plist>


It looks like a lot, but it is very easy once you get the hang of it.

Once you have these items you place them into Library/PreferenceLoader/Preferences
Close your settings app and reopen it. You will see your preferences.

Now to cydget.

<script type="text/cycript">
   try{
        var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.JunesiPhone.demo.plist"];
       if(settings!=null){
image=settings.options;
       }
    }catch(err){
        alert(err);
    }
</script>

Thats pretty much it for cydget. This script will pull the plist listed. This plist is created by the preferenceloader, and you set the name for it under your defaults key. So once this toggle, switch etc is pressed it updates this plist.

If you see above there is a part of the plist that is bold. It is pertaining to this script I just wrote. You can see our key is called options. Also take note that I gave our cycript a var of settings.

Therefore if you alert(settings); it will show our plist entries. If you alert(settings.options); then it will show the value of the key options. You can now use this key in your javascript.

For the example I used image=settings.options. I passed this value to image. now if you alert(image); it will alert this value.

In the demo code I wrote, I used image to decide on which image to show as the background. Here is the complete html

<!DOCTYPE html>
<html>
<head>
<title>Demo Cydget</title>
</head>
<body>

 <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

<style type="text/css">#wallpaper{position: absolute;top:0px;left:0pc;}</style>
<div id="wallpaper"><img src="1.jpg" width="320"></div>
<script type="text/javascript">
image="1";
</script>

<script type="text/cycript">
   try{
        var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.JunesiPhone.demo.plist"];
       if(settings!=null){
image=settings.options;
       }
    }catch(err){
        alert(err);
    }
</script>

<script>
width="320"
imageset=image+".jpg"
document.getElementById("wallpaper").innerHTML='<img width='+width+' src='+imageset+'>'
</script>
</body>
</html>

Also note I set the var at the top image="1"; if it doesn't detect a plist, or doesn't read it. Then it will default to that value. If it does, then it changes it accordingly.

The complete code is located in the Video description. Enjoy

A few cycripts

These are a few things you can 1. Run from terminal while in cycript. 2. Add to your lockscreens to use.

Turn on the lockscreen
[[SBBacklightController sharedInstance] turnOnScreenFullyWithBacklightSource:1]
Unlock iPhone (Terminal only)
[[SBLockScreenManager sharedInstance] _finishUIUnlockFromSource:1 withOptions:1]
Stop dimming of the lockscreen
[[SBBacklightController sharedInstance] cancelLockScreenIdleTimer]
Pull info from settings set plist
 var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.JunesiPhone.miWeather.plist"];
Pull info from settings code
 

script type="text/cycript"
   try{
        var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.JunesiPhone.miWeather.plist"];
       if(settings!=null){
       }
    }catch(err){
        alert(err);
    }
/script
SB switcher stuff
 
[[SBUIController sharedInstanceIfExists]_toggleSwitcher]

[[SBUIController sharedInstanceIfExists]dismissSwitcherAnimated:YES]

[[SBUIController sharedInstanceIfExists]getRidOfAppSwitcher]
Unlock with passcode
 
[[SBLockScreenManager sharedInstance] attemptUnlockWithPasscode:@"1234"]
Small status on SB
 
SBLockScreenViewController.messages['statusBarStyle']=function(){return 0}
Allow folders to be placed in folders.
 
SBIconView.messages['canReceiveGrabbedIcon:'] = function (icon){ return YES; }
See if notifications are showing on the Lockscreen
 
[[[SBLockScreenManager sharedInstance] lockScreenViewController] lockScreenIsShowingBulletins];
Use location services
 
manager = [[[CLLocationManager alloc] initWithEffectiveBundle: [NSBundle bundleForClass: CLLocationManager.class]]autorelease]
    manager.delegate = CLLocationManagerDelegate;
    manager.desiredAccuracy = kCLLocationAccuracyBest;
    [manager startUpdatingLocation];
    var GPS = manager.location.coordinate;
    [manager stopUpdatingLocation];
    var Latitude = JSON.stringify(GPS[0]);
    var Longitude = JSON.stringify(GPS[1]);
See if location services is enabled
 
[[CLLocationManager sharedManager] locationServicesEnabled];
Detect if passcode is on
 
[[SBDeviceLockController sharedController]isPasscodeLocked];
Open url in safari
 
mySafari = [UIApplication sharedApplication];
    myURL = [[NSURL alloc]initWithString:@""+url];
    [mySafari openURL:myURL]; //myUrl is your link
    [myURL release];
Disable lock bounce iOS7.1
 
SBLockScreenView.messages['hintDisplacement']=function(){return 0}
Get app notification badge
 
SBIconController.sharedInstance.model.leafIconsByIdentifier["com.apple.MobileSMS"].badgeValue;
Device stuff
 
[[UIDevice currentDevice] name];
[[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/var/mobile" error:NULL];
[NSProcessInfo processInfo].physicalMemory;
[NSProcessInfo processInfo].processorCount;
[NSProcessInfo processInfo].operatingSystemVersionString;
[NSProcessInfo processInfo].systemUptime;
Battery Percent
 
[[SBUIController sharedInstance]batteryCapacityAsPercentage];
Unlock device on iOS7. Thanks to Saurik for his help on this one.
 
   [^void(){[[UIApplication sharedApplication] launchApplicationWithIdentifier:@""+bundle suspended:NO];}
  performSelectorOnMainThread: @selector(invoke) withObject: nil waitUntilDone: NO];
Hide LS items
 
 [[[[SBLockScreenManager sharedInstance]lockScreenViewController]lockScreenView]setSlideToUnlockHidden:1 forRequester:1];
 [[SBAppStatusBarManager sharedInstance] hideStatusBar];
 [[[[SBLockScreenManager sharedInstance]lockScreenViewController]lockScreenView]setTopGrabberHidden:1 forRequester:1];
 [[[[SBLockScreenManager sharedInstance]lockScreenViewController]lockScreenView]setBottomGrabberHidden:1 forRequester:1];
Get last touched icon
 
 [[SBIconController sharedInstance]lastTouchedIcon];
Home button tap by code
 
 [[SBIconController sharedInstance]handleHomeButtonTap];
Display icons or bundles
 
 [[SBApplicationController sharedInstance]allDisplayIdentifiers]
[[SBApplicationController sharedInstance]allApplications]
Hope this helps, has taken me quite awhile to get most of these. Sometimes weeks at a time to figure one out. If you have any let me know, and I will add them. Most all of these can be found in LockBuilder Evo