Skip to content

Instantly share code, notes, and snippets.

@naotokui
naotokui / gist:4122008
Created November 20, 2012 23:32
Background execution with UIBackgroundTaskIdentifier
// バックグラウンド処理のスタートを宣言
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
/* ここでやりたい処理をする */
// バックグラウンド処理の終了
if (bgTask != UIBackgroundTaskInvalid){
@naotokui
naotokui / gist:4316601
Created December 17, 2012 08:15
How to tell the state of iOS application i.e, background, active, inactive.
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ...
// UIApplicationStateActive,
// UIApplicationStateInactive,
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@naotokui
naotokui / gist:4343823
Created December 20, 2012 08:34
Update a specific cell in tableview
- (void)reloadRow: (NSInteger) row inSection:(NSInteger) section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
NSArray *indexPaths = [[NSArray alloc] initWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; //UITableViewRowAnimationFace or whatever
[indexPaths release];
}
@naotokui
naotokui / gist:4523569
Created January 13, 2013 11:12
Reset NSUserDefaults
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
@naotokui
naotokui / gist:4984986
Last active December 13, 2015 22:29
Sending image via Line.app Lineで画像データを送る方法
NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"Flower.jpg"] , 0.5);
UIPasteboard* pasteboard = [UIPasteboard pasteboardWithName: LINE_PASTEBOARD create: YES];
[pasteboard setData: data forPasteboardType: (NSString *)kUTTypeJPEG];
// LINE
NSString *escapedStr = [LINE_PASTEBOARD stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *urlStr = [NSString stringWithFormat:@"line://msg/image/%@", escapedStr];
NSURL *sndUrl = [NSURL URLWithString:urlStr];
if ([[UIApplication sharedApplication] canOpenURL:sndUrl]) {
@naotokui
naotokui / 0_reuse_code.js
Created October 25, 2013 00:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
+ (ClassName *)sharedInstance {
static dispatch_once_t once;
static ClassName *sharedInstance;
dispatch_once(&once, ^ { sharedInstance = [[ClassName alloc] init]]; });
return sharedInstance;
}
@naotokui
naotokui / file0.m
Created December 11, 2013 03:57
iOS 64bit対応ではまったところ (書きかけ) ref: http://qiita.com/naotokui/items/38c9176ebece6aadf172
#if defined(__LP64__) && __LP64__
# define CGFLOAT_TYPE double
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
#else
# define CGFLOAT_TYPE float
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
@naotokui
naotokui / gist:f70eddddbcb7c96f6a07
Created August 21, 2014 01:34
check if a number is 2^N
if ((num & (num - 1)) == 0){
// num is 2^N
}