Skip to content

Instantly share code, notes, and snippets.

@msching
msching / addressesForHostname.m
Last active May 9, 2016 10:57
addressesForHostname
+ (NSArray *)addressesForHostname:(NSString *)hostname
{
if (!hostname)
{
return nil;
}
// Get the addresses for the given hostname.
CFHostRef hostRef = CFHostCreateWithName(kCFAllocatorDefault, (__bridge CFStringRef)hostname);
BOOL isSuccess = CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil);
@msching
msching / AVPlayerCaching.m
Last active August 15, 2016 17:37 — forked from anonymous/AVPlayerCaching.m
using localfile if file is created
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@msching
msching / updateNowPlayingCenter
Last active March 30, 2016 03:09
update NowPlayingCenterInfo for iOS 8.2 (even if you only wish to update the artwork).
- (void)updateNowPlayingCenter:(NSDictionary *)info
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.2") && SYSTEM_VERSION_LESS_THAN(@"8.3"))
{
NSString *zeroLengthString = @"\u200B";
NSString *title = info[MPMediaItemPropertyTitle];
NSString *currentTitle = [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo[MPMediaItemPropertyTitle];
NSUInteger index = [currentTitle rangeOfString:zeroLengthString].location;
if (index == NSNotFound)
{
@msching
msching / UIDevice + ProcessesAdditions
Created February 27, 2015 05:20
A UIDevice category for getting the running processes on an iOS device. Based on something floating about on the web by Landon Fuller. Cleaned it up a bit and changed so it returns an NSArray of NSDictionary[s].
// .h
@interface UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses;
@end
// .m
#import <sys/sysctl.h>
@implementation UIDevice (ProcessesAdditions)