Skip to content

Instantly share code, notes, and snippets.

View priore's full-sized avatar

Priore priore

View GitHub Profile
@priore
priore / gist:7163483
Created October 25, 2013 23:39
How to invoke a method in a class via their string names
+ (void)invokeMethodNamed:(NSString*)methodName withObject:(id)object classNamed:(NSString*)className
{
id class = NSClassFromString(className);
if (class) {
SEL selector = NSSelectorFromString(methodName);
if ([class respondsToSelector:selector]) {
// static method +(void)
[class performSelector:selector withObject:object];
} else {
// new instanced method -(void)
@priore
priore / gist:7163490
Created October 25, 2013 23:40
Icon with symbol of the beta version
//
// Icon with symbol of the beta version instead of the number of badges.
//
// The first thing to note is that the method uses a private API
// so you don't want the code included in your App Store build.
// You can use conditional compilation to achieve this.
//
// original post from @sgaw
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@priore
priore / gist:7163493
Created October 25, 2013 23:41
UIWebView asynchronous javascript call
//
// UIWebView asynchronous javascript call
//
// javascript function
NSString *javascriptString = @"my_function();";
// allocated UIWebView
[webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:javascriptString waitUntilDone:NO]
@priore
priore / gist:7163498
Created October 25, 2013 23:41
Random numbers and random boolean values
@implementation NSNumber (Randomizer)
+ (NSNumber*)randomNumberWithMin:(NSInteger)min max:(NSInteger)max
{
if (min>max) {
int tempMax=max;
max=min;
min=tempMax;
}
int randomy=arc4random() % (max-min+1);
@priore
priore / gist:7163501
Created October 25, 2013 23:42
How to manage the image asynchronously from a UIImagePicker
// How to manage the image asynchronously from a UIImagePickerController
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// hide UIImagePickerController
[picker dismissViewControllerAnimated:YES completion:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
if (photo) {
@priore
priore / gist:7163510
Created October 25, 2013 23:42
SDWebImage extended with alternate URL
//
// SDWebImage author: @Olivier_Poitrey
// source code https://github.com/rs/SDWebImage
//
// Extension author: @DaniloPriore
//
#import "SDWebImageCompat.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"
#import "objc/runtime.h"
@priore
priore / gist:7163512
Created October 25, 2013 23:43
UIImage from icon app
+ (UIImage*)imageFromIconApp {
NSString *iconName = nil;
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSArray *iconfiles = [info valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"];
if (iconfiles == nil || [iconfiles count] == 0) iconfiles = [info objectForKey:@"CFBundleIconFiles"];
if (iconfiles != nil && [iconfiles count] > 0) {
iconName = [iconfiles objectAtIndex:0];
} else {
@priore
priore / gist:7163516
Created October 25, 2013 23:43
User-Agent for all UIWebView in your app
// User-Agent for all UIWebView in your app, originally posted by @_kims
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
@priore
priore / gist:7163520
Created October 25, 2013 23:44
Set property values ​​from a NSDictionary
//
// NSObject+NSDictionary.h
//
@interface NSObject (NSDictionary)
- (void)setValuesWithDictionary:(NSDictionary*)dict;
@end
//
// NSObject+NSDictionary.m
//
@priore
priore / gist:7163524
Created October 25, 2013 23:44
Force Facebook Logout
// force close
[[FBSession activeSession] closeAndClearTokenInformation];
[[FBSession activeSession] close];
[FBSession setActiveSession:nil];
// remove FB cookie
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies]) {
NSString *domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:@"facebook"];