[Twitter]ktyrtw
Twitterクライアントをリニューアルしました。まだ未完成。
/twitter/
※追記 ほぼ完成。
バンドルしたhtmlファイルをUIWebViewにロードする
NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"]; [webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
暗号化・複合化
define('KEY', 'bsrNaTwou3PJJbUHMVp20BW0JFxszbOdTaYTtY2jD26TxNFZ');//getRandomStr(48)で取得 define('IV', 'rfKvr+rLztklJ0/6hc8ZmrILlMLVoan6ltu/SR2Bvzg=');//getCryptIV()で取得 $str='あいうえお'; $crypted_str = getEncrypt($str); echo $crypted_str; echo '<br/><br/>'; $decrypted_str = getDecrypt($crypted_str); echo $decrypted_str; exit; function getEncrypt($data) { $resource = mcrypt_module_open('rijndael-256', '', 'ofb', ''); $iv = base64_decode(str_rot13(IV)); $ks = mcrypt_enc_get_key_size($resource); $key = substr(md5(KEY), 0, $ks); mcrypt_generic_init($resource, $key, $iv); $encrypt = mcrypt_generic($resource, $data); mcrypt_generic_deinit($resource); mcrypt_module_close($resource); return base64_encode($encrypt); } function getDecrypt($data) { $resource = mcrypt_module_open('rijndael-256', '', 'ofb', ''); $iv = base64_decode(str_rot13(IV)); $ks = mcrypt_enc_get_key_size($resource); $key = substr(md5(KEY), 0, $ks); mcrypt_generic_init($resource, $key, $iv); $decrypt = mdecrypt_generic($resource, base64_decode($data)); mcrypt_generic_deinit($resource); mcrypt_module_close($resource); return $decrypt; } function getCryptIV(){ $key = getRandomStr(48); $td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); $iv = base64_encode($iv); mcrypt_module_close($td); return $iv; } function getRandomStr($length=8){ $str=''; for ($i = 0, $str = null; $i < $length; ) { $num = mt_rand(0x30, 0x7A); if ((0x30 <= $num && $num <= 0x39) || (0x41 <= $num && $num <= 0x5A) || (0x61 <= $num && $num <= 0x7A)) { $str .= chr($num); $i++; } } return $str; }
INSERT文を作る
echo getInsertQueryByKey('system_table', array('name','gender'), array( array('jeff','male'), array('pola','female') ) ); function getInsertQueryByKey($tableName,$columns,$datas){ //SQLite古いバージョン $w=array(); $column = implode(',', $columns); $query="INSERT INTO {$tableName} ({$column}) SELECT "; $tmp=array(); foreach ($columns as $index => $columnName) { $tmp[] = "'". $datas[0][$index] . "'" . ' AS ' . $columnName; } $query .= implode(', ', $tmp); $w[]=$query; foreach ($datas as $index => $data) { if($index<1)continue; $tmp=array(); foreach ($columns as $index2 => $columnName) { $tmp[]=$data[$index2]; } $w[]="'".implode("', '", $tmp)."'"; } return implode(' UNION ALL SELECT ', $w).';'; /* MySQL or SQLite(バージョン 3.7.11以降) $queryValues=array(); foreach ($datas as $index => $value) { $values=array(); foreach ($value as $index2 => $value2) { $values[]="'".$value2."'"; } $queryValues[]='('.implode(',', $values).')'; } $column=implode(',', $columns); $value=implode(',', $queryValues); $sql="INSERT INTO {$tableName} ({$column}) VALUES {$value};"; return $sql; */ }
INSERTで複数のデータを挿入
INSERT INTO system_table (name,gender) SELECT 'jeff' AS name, 'male' AS gender UNION ALL SELECT 'pola', 'female';
MySQL or SQLite(バージョン 3.7.11以降)
INSERT INTO system_table (name,gender) VALUES ('jeff','male'),('pola','female');
UINavigationController-スワイプでのpopViewControllerAnimatedを無効にする
UINavigationController*nav.interactivePopGestureRecognizer.enabled=NO;
XMLDictionary
NSDictionary*xmldic=[NSDictionary dictionaryWithXMLString:xmlString];
<ZIP_result> <result name="ZipSearchXML"/> <result version="1.01"/> <result request_url="http%3A%2F%2Fzip.cgis.biz%2Fxml%2Fzip.php%3Fzn%3D0600000"/><result request_zip_num="0600000"/> <result request_zip_version="none"/> <result result_code="1"/> <result result_zip_num="0600000"/> <result result_zip_version="0"/> <result result_values_count="1"/> <ADDRESS_value> <value state_kana="ホッカイドウ"/> <value city_kana="サッポロシチュウオウク"/> <value address_kana="イカニケイサイガナイバアイ"/> <value company_kana="none"/> <value state="北海道"/> <value city="札幌市中央区"/> <value address="none"/> <value company="none"/> </ADDRESS_value> </ZIP_result>
上記のようなxmlStringだとすると
“北海道”を取得するにはこうする。
NSString*state=[xmldic valueForKeyPath:@"ADDRESS_value.value"][4][@"_state"];
シングルトンクラス
DataBaseManager.h
#import <Foundation/Foundation.h> #import "EGODatabase.h" @interface DataBaseManager : NSObject{ } + (DataBaseManager*)sharedInstance; @end
DataBaseManager.m
#import "DataBaseManager.h" @implementation DataBaseManager + (DataBaseManager*)sharedInstance { static DataBaseManager* _instance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[DataBaseManager alloc]initSharedInstance]; }); return _instance; } - (id)initSharedInstance { self = [super init]; if (self) { //初期化 } return self; } @end
使うとき
DataBaseManager*dbm=[DataBaseManager sharedInstance];