Skip to content

Instantly share code, notes, and snippets.

@Eridana
Eridana / Install cocoapods
Created February 16, 2015 12:38
Install cocoapods
1) $ sudo gem install cocoapods (gem will get installed in Ruby inside System library)
2) create a xcode project
3) Open terminal
4) cd "$ path to your project root directory"
5) $ touch podfile
6) open -e podfile
7) pod 'AFNetworking', '0.9.1' (Cocoapods Podfile name )
8) pod install
@Eridana
Eridana / UIAlertView and UIAlertController
Created January 17, 2015 14:42
UIAlertView and UIAlertController
if ( NSClassFromString(@"UIAlertController") != nil ) {
//make and use a UIAlertController
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Вы не авторизованы"
message:@"Пожалуйста введите логин и пароль"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
@Eridana
Eridana / Crop UIImage
Created January 15, 2015 10:16
Crop UIImage
- (UIImage *)imageByCroppingImage:(UIImage *)image toSize:(CGSize)size
{
// not equivalent to image.size (which depends on the imageOrientation)!
double refWidth = CGImageGetWidth(image.CGImage);
double refHeight = CGImageGetHeight(image.CGImage);
double x = (refWidth - size.width) / 2.0;
double y = (refHeight - size.height) / 2.0;
CGRect cropRect = CGRectMake(x, y, size.height, size.width);
@Eridana
Eridana / AppDelegate
Last active August 29, 2015 14:13
Set local notification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
[[UIApplication sharedApplication] registerUserNotificationSettings:
[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
@Eridana
Eridana / Get currently active storyboard
Created December 26, 2014 17:35
Get active storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
@Eridana
Eridana / RootController
Created December 11, 2014 10:53
Storyboard set root controller and custom navigation controller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *controller =[storyboard instantiateViewControllerWithIdentifier:@"myViewController"];
MyNavigationController* nav = [[MyNavigationController alloc] initWithRootViewController:controller];
@Eridana
Eridana / Good macros for NSLog (from SO)
Created December 4, 2014 11:22
Good macros for NSLog (from SO)
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
@Eridana
Eridana / Check device type and etc (ios)
Created December 4, 2014 10:02
Check device type and etc (ios)
#include <sys/sysctl.h>
- (NSString *)platform
{
int mib[2];
size_t len;
char *machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
@Eridana
Eridana / Detect network type (ios)
Last active August 26, 2019 03:40
Detect network type (ios)
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import "Reachability.h"
@implementation DeviceInfo
- (NSString *)getNetworkType
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];