Monday, January 19, 2015

Getting Calendar Event with Cycript

Testing in Cycript

This is how I would go about finding the Calendar Event in Cycript.
First I would look at Apple's documentation on the calendar. LINK <- this can usually be found by searching their documents or using Google.

Not far down this page you will see listing 1-1.
NSCalendar *calendar = [NSCalendar currentCalendar];

Easy enough here is how we can get the calendar object, it even shows us how to retrieve events. Lets work on altering this to run in Cycript. First log into cycript via terminal. To do this type in ssh root@yourip it will ask for your password enter it. Default password is alpine. Then type cycript -p SpringBoard


You are now logged into Cycript you can tell by the cy#

We start adding what the Apple dev center says. As you see below I followed most of what the Apple site shown, only removing things which look like NSCalendar *-  as we only need a variable.


Lets go line by line.

calendar = [NSCalendar currentCalendar];
Gets the calendar wrapper

oneDayAgoComponents = [[NSDateComponents alloc] init];
Gets the current date

oneDayAgoComponents.day = -1; 
Sets the day -1 from today

oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents toDate:[NSDate date]options:0];
Takes the calendar wrapper and gets a date from the oneDayAgoComponents which will return a complete date for today.

!.. Apple uses oneYearFromNowComponents we don't need one year from now instead we need a day or two from now.

nextDayFromNowComponents = [[[NSDateComponents alloc] init]autorelease];
Allocate (create) a new date component

nextDayFromNowComponents.day = 1;
set it to a day after current

nextDayFromNow = [calendar dateByAddingComponents: nextDayFromNowComponents toDate: [NSDate date]options: 0];
get complete date.

store = [[[EKEventStore alloc] init]autorelease];
Allocate (create) a new EKEventStore

predicate = [store predicateForEventsWithStartDate: oneDayAgo endDate: nextDayFromNow calendars: nil];
Take the store and add our dates. It will return the days we want to get. (EKEventPredicate start:1/18/15, 7:27 PM; end:1/20/15, 7:29 PM; cals:(null))

events = [store eventsMatchingPredicate: predicate];
Call the store and get the matches for our dates. This will return all events for these days. As you see above, which I will post again here. It gives us events.


The events returned is an object. So we can pull info just as you would any object.

events[0] would return the first event
events[1] would return the second and so on.

Once we get each event say event[0] (first event) we can get certain values such as title, location, and any other info in the object.



events[0].title
shows current event title which is what we are going to put in our cydget.


Creating the Cydget

I will start by thinking you have the basic concept how to create the cydget and jump straight into the html code.



Here we do basically the same thing we did in Cycript itself. More than likely if it works in Cycript it will work the same way in Cydget.

At the end of the getcalendarEvents I put an if statement if(events) this means if there is an event it will return events[0].title. There needs to be and could be more optimization here. For example and else{} statement could be added incase there is no event.


Here is a more advanced process that will give you all events instead of one.














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

Saturday, September 14, 2013

Running Cycript from Cydgets

My main objective here.

At this moment in time, I have no interest in tweaks. Cycript seems like a great tool for the tweak maker.

Cycript is great for executing code while runtime. I can image how great this is for Tweak developers.

What about themers? One issue, themers theme. Majority are graphic designers, and picked up how to use some code for there lockscreens. With knowing a little about code, you can run script that affect apples code at runtime. (basic javascript)

Saurik makes it very simple with Cydgets. I personally have created a lockscreen (Only using Cydgets)
It will unlock itself in 10 seconds. Great thing is its not a trick. Meaning it actually uses apples code to unlock the device.

You can also write files to text. Tweaks like infoStats. This can be done from inside an html. No tweak needed. Cycript merges that boundary.

Want to get values from apps? Sure just use cycript.  Display missed calls on your lockscreen for your theme? Yes, Use an unlock other than slide to unlock? YES!  Anything is possible, and is worth looking at.  I will explain my code below.


To run [[SBAwayController sharedAwayController] unlockWithSound:NO] we first need to create a script, this way cycript knows it needs to run this code. You can do this by

<script type='text/cycript'> Your Code Here</script>

Standard script, but notice text/cycript.  Now we can insert obj c right here O_o 

<script type='text/cycript'> 
setTimeout(function(){unlock()}, 10000);
function unlock(){
  [[SBAwayController sharedAwayController] unlockWithSound:NO]
}
</script>

The entire code. It is set to run after a few seconds. This means if you put this  in cydgets as a cydget:P It will unlock your phone after the timeset.

ISSUES: So far I have had one issue. If I connect this to a button. Meaning if I press a button it executes this code, then I will go into safe mode. At this time i'm not sure why, but I will report back. Working as timeout and not button, makes me thing that maybe the pressed action needs to be canceled. Not sure yet. This does work, reason I am posting. I myself didn't see it possible. It surely is.





Cycript

Woah!  That about sums it up.. Within a few days I have learned things, I could only dream of. One as a developer/themer/coder. The other just as a normal Jailbreaker.  I would like to share my findings with you.

Reason for this Cydgets blog, is learning new things is a pain! Sometimes hour upon hours researching until you find that one piece that the last tutorial missed.  Although i'm not here to give you all the answers. I do want to share what i've learned.

A new page has been added to the blog. Cycript  At this point i'm speechless. Cannot find the exact adjective to describe what kind of tool Cycript is. So its Amazing.

You can view my page here: Cycripts http://cydgets.blogspot.com/p/cycript-pronounced-ssscript.html

 I am new to this tool, as with Cydgets.  Comments are very welcome.




Thursday, September 12, 2013

Editing any lockscreen to use image set from setbackground.cydget

With the setbackground.cydget, I have created a way to pick an image from your camera roll. Then set it to your lockscreen. What makes this great is, its easier to set wallpapers, and it can work across any cydget. I'll explain.

I can save this image you picked for further use. You can read more on that here.

I save this image file in LocalStorage. It is not a link to the image, but the actual image itself.

Most of the time you would create a wallpaper 

<div id="wallpaper"><img src=""/></div>

No matter what the image src you can change this image at any time by.

<style>#wallpaper{background: url('')}</style>

So if I was to take our saved photo. Which is saved as userbg. I just have to call it in my html.
any time to get something from local storage you can locatStorage.getItem("your saved entry")

We can open any lock background and add this script.

load();

function load(){

var getitems = localStorage.getItem("userbg");


 $('#wallpaper').css('background-image', 'url(' + getitems + ')');
}

All this does is pull the image from out storage, then applies it to the wallpaper via background-image. This in return overwrites whatever wallpaper the lockscreen used, and uses your own wallpaper. You can now pick any wallpaper via set background and it will set any cydget background to that image.