Skip to content

Instantly share code, notes, and snippets.

View jonahsiegle's full-sized avatar

Jonah Siegle jonahsiegle

View GitHub Profile
@jonahsiegle
jonahsiegle / Signal.swift
Created November 14, 2017 17:53
Get Signal Strength on the iPhone X
func getSignalStrengthiPhoneX() -> Int {
let application = UIApplication.shared
let statusBarView = application.value(forKey: "statusBar") as! UIView
let statusBar = statusBarView.value(forKey: "statusBar") as! UIView
let foregroundView = statusBar.value(forKey: "foregroundView") as! UIView
for subview in foregroundView.subviews {
if subview.subviews.count > 0 {
for child in subview.subviews {
@jonahsiegle
jonahsiegle / gist:054f36dca9f961dd3d59
Created April 30, 2014 16:37
Converts NSTimeInterval into a verbal NSString format.
- (NSString *)readableTimeWithDuration:(NSTimeInterval)timeDuration{
NSUInteger roundedTime = round(timeDuration);
unsigned long days = roundedTime / 86400;
unsigned long hours = roundedTime / 3600;
unsigned long minutes = (roundedTime / 60) % 60;
NSString *dayLabel = days > 1 ? @"Days" : @"Day";
NSString *hourLabel = hours > 1 ? @"Hours" : @"Hour";
@jonahsiegle
jonahsiegle / gist:9837352
Created March 28, 2014 16:45
Check if two NSDate objects are on the same day.
- (BOOL)isSameDayWithDateOne:(NSDate *)dateOne dateTwo:(NSDate *)dateTwo{
NSCalendar *calender = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *compOne = [calender components:unitFlags fromDate:dateOne];
NSDateComponents *compTwo = [calender components:unitFlags fromDate:dateTwo];
return ([compOne day] == [compTwo day] && [compOne month] == [compTwo month] && [compOne year] == [compTwo year]);
//Access the oppropriate entity
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:((AppDelegate *)[[UIApplication sharedApplication]delegate]).managedObjectContext];
//Creating a child context to use in the background thread
NSManagedObjectContext *context = [[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType];
//Setting the parent context
context.parentContext = ((AppDelegate *)[[UIApplication sharedApplication]delegate]).managedObjectContext;
//Call fetching in background
if (![[NSUSerDefaults standardUserDefaults] boolForKey:@"1.1 First Launch"]){
[[NSUserDefaults standardUserDefaults]setBool:TRUE forKey:@"1.1 First Launch"];
[[NSUserDefaults standardUserDefaults]synchronize];
//Fist launch code to execute.
}
@jonahsiegle
jonahsiegle / gist:3346925
Created August 14, 2012 06:29
NSUserDefaults Fix
//set
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"clientToBroadcastTo"])
[[NSUserDefaults standardUserDefaults] setObject:@"Messages" forKey:@"clientToBroadcastTo"];
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"autoCheckForUpdates"])
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"autoCheckForUpdates"];
[[NSUserDefaults standardUserDefaults] synchronize];
//edit
- (void)playPause:(id)sender {
player = [MPMusicPlayerController applicationMusicPlayer];
if ([songs count] > 0) {
if (isPlaying) {
NSLog(@"Playing music");
[player pause];