Category Archives: IOS

「ios入門」iosでudidを取得するサンプルコード

サンプルコード:
-(void) setKeyChainValue
{
KeychainItemWrapper *keyChainItem=[[KeychainItemWrapper alloc]initWithIdentifier:@”TestUUID” accessGroup:@”XXXXXX.h.こんにちは”];
NSString *strUUID = [keyChainItem objectForKey:(id)kSecValueData];
if (strUUID==nil||[strUUID isEqualToString:@””])
{
[keyChainItem setObject:[self gen_uuid] forKey:(id)kSecValueData];
}
[keyChainItem release];

}

-(NSString *) gen_uuid
{
CFUUIDRef uuid_ref=CFUUIDCreate(nil);
CFStringRef uuid_string_ref=CFUUIDCreateString(nil, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid=[NSString stringWithString:uuid_string_ref];
CFRelease(uuid_string_ref);
return uuid;
}

keychainを操作するツール

https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_m.html

 

Objective-C でシングルトンパターン(Singleton)のサンプルコード

サンプルコード:
static Config * instance = nil;
+(Config *) Instance
{
@synchronized(self)
{
if(nil == instance)
{
[self new];
}
}
return instance;
}

+(id)allocWithZone:(NSZone *)zone
{
@synchronized(self)
{
if(instance == nil)
{
instance = [super allocWithZone:zone];
return instance;
}
}
return nil;
}

IOSインストール後初めて起動するかどうかを判断する方法

サンプルコード:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@”firstLaunch”]){
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@”firstLaunch”];
//初めて起動
}else{
//初めてではない起動
}

「ios入門」Documentディレクトリにフォルダを作成、保存、読み取り及びファイルを削除

サンプルコード:
//DocumentsディレクトリにLaunchImageフォルダを作成
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@”Documents”] stringByAppendingPathComponent:@”LaunchImage”];
NSLog(@”%@”,path);

NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = FALSE;
BOOL isDirExist = [fileManager fileExistsAtPath:path isDirectory:&isDir];
if(!(isDirExist && isDir))

{
BOOL bCreateDir = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
if(!bCreateDir){
NSLog(@”フォルダを作成失敗!”);
}
NSLog(@”フォルダを作成成功ファイルパス%@”,path);
}

UIImage *image=[UIImage imageWithContentsOfFile:@”startnews24image.png”];
NSData *data = UIImagePNGRepresentation(image);
//LaunchImageフォルダに「startnews24image.png」を保存、
BOOL isSaved= [fileManager createFileAtPath:[path stringByAppendingString:@”/image1.png”] contents:data attributes:nil];
NSLog(@”画像保存状態:%d”,isSaved);

//保存した画像を取得
UIImage *newimage=[UIImage imageWithContentsOfFile:[path stringByAppendingString:@”/image1.png”]];

//ファイルを削除
BOOL isDelete=[fileManager removeItemAtPath:path error:nil];
NSLog(@”%d”,isDelete);

「ios入門」jsonを解析する方法

1.jsonからdictへ解析
-(void)fetchedData:(NSData*)responseData {//parse out the json dataNSError* error;
NSDictionary* json =[NSJSONSerialization
JSONObjectWithData:responseData //1

options:kNilOptions
error:&error];

NSArray* latestLoans =[json objectForKey:@”loans”]; //2

NSLog(@”loans: %@”, latestLoans); //3
}

2.オブジェクトからjson stringに変換
//build an info object and convert to json
NSDictionary* info =[NSDictionary dictionaryWithObjectsAndKeys:[loan objectForKey:@”name”],
@”who”,
[(NSDictionary*)[loan objectForKey:@”location”]
objectForKey:@”country”],
@”where”,
[NSNumber numberWithFloat: outstandingAmount],
@”what”,
nil];

//convert object to data
NSData* jsonData =[NSJSONSerialization dataWithJSONObject:info
options:NSJSONWritingPrettyPrinted error:&error];

//print out the data contents
jsonSummary.text =[[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];

3.dicにjsonメソッドを追加

@interfaceNSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end

@implementationNSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress{
NSData* data =[NSData dataWithContentsOfURL:[NSURL URLWithString: urlAddress]];
__autoreleasing NSError* error =nil;
id result =[NSJSONSerialization JSONObjectWithData:data
options:kNilOptions error:&error];
if(error !=nil)returnnil;
return result;
}

-(NSData*)toJSON{
NSError* error =nil;
id result =[NSJSONSerialization dataWithJSONObject:self
options:kNilOptions error:&error];
if(error !=nil)returnnil;
return result;
}@end

4.利用サンプル
NSDictionary* myInfo =[NSDictionary dictionaryWithContentsOfJSONURLString:@”http://www.yahoo.com/news.json”];
NSDictionary* information =[NSDictionary dictionaryWithObjectsAndKeys:@”orange”,@”apple”,@”banana”,@”fig”,nil];
NSData* json =[information toJSON];

5.jsonを判断
BOOL isTurnableToJSON =[NSJSONSerialization isValidJSONObject: object]

「IOS入門」ActionSheetPickerをカスタマイズするサンプルコード

サンプルコード:
– (void)showActionSheetPicker {
UIView *masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewSize.width, 260)];
UIToolbar *pickerToolbar = [self createPickerToolbarWithTitle:self.title];
[pickerToolbar setBarStyle:UIBarStyleBlackTranslucent];
[masterView addSubview:pickerToolbar];
self.pickerView = [self configuredPickerView];
NSAssert(_pickerView != NULL, @”Picker view failed to instantiate, perhaps you have invalid component data.”);
[masterView addSubview:_pickerView];
masterView.backgroundColor=[UIColor whiteColor];
[self presentPickerForView:masterView];
}

Pale Moon 24.7.1 for Mac ダウンロード

ダウンロード
提供元サイトからダウンロード

対象OS:
64-bit Mac OSX only. OSX requirement is 10.8.3 or later

「ios入門」ios開発用ライブラリサイト紹介

1.SSToolkit (UIライブラリ)

SSToolkit is a collection of well-documented iOS classes for making life easier by solving common problems all iOS developers face.

http://sstoolk.it/

 

2.GPUImage(画像処理ライブラリ)

The GPUImage framework is a BSD-licensed iOS library that lets you apply GPU-accelerated filters and other effects to images, live camera video, and movies. In comparison to Core Image (part of iOS 5.0), GPUImage allows you to write your own custom filters, supports deployment to iOS 4.0, and has a simpler interface

https://github.com/BradLarson/GPUImage

3.SocketRocket(WebSocketクライアント)

特徴

  • TLS (wss) support. It uses CFStream so we get this for free
  • Uses NSStream/CFNetworking. Earlier implementations used dispatch_io, however, this proved to be make TLS nearly impossible. Also I wanted this to work in iOS 4.x. (SocketRocket only supports 5.0 and above now)

https://github.com/square/SocketRocket

 

4.HockeyKit (ios Ad-Hoc自動更新フレームワーク)

特徴
Over-The-Air Distribution
Statistics
Multi Platform Support
Hosted Solution

http://hockeykit.net/

5.JSONKit(JSONデータアクセスツール)

JSONKit is dual licensed under either the terms of the BSD License, or alternatively under the terms of the Apache License, Version 2.0.

https://github.com/johnezang/JSONKit

Xcode6とXcode5でアプリ名(app nam)eを取得する方法比較

1.Xcode5 アプリ名(app name)を取得
NSString *proName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleDisplayName”];
NSLog(@”dicName ==== %@”,[[NSBundle mainBundle] infoDictionary]);

出力結果
CFBundleDisplayName = TestOfButton;
CFBundleName = TestOfButton;

2.Xcode6 アプリ名(app name)を取得
NSString *proName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleName”];
NSLog(@”dicName ==== %@”,[[NSBundle mainBundle] infoDictionary]);
出力結果:CFBundleName = TestOfButton;

3.Xcode6に info.string がありません、Info.plist のみある

「ios入門」IOSプラットフォームでplistを作成する方法

処理コード:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kindsoft</key>
<string>software-package</string>
<key>url</key>
<string>http://XXX.XXX.XXX.XXX:8080/irec/client/irec_iphone/aywiPhone.ipa</string>
</dict>
<dict>
<key>kindsoft</key>
<string>full-size-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>http://XXX.XXX.XXX.XXX:8080/irec/client/irec_iphone/aywiPhone-512.png</string>
</dict>
<dict>
<key>kindsoft</key>
<string>display-image</string>
<key>needs-shine</key>
<false/>
<key>url</key>
<string>http://XXX.XXX.XXX.XXX:8080/irec/client/irec_iphone/aywiPhone-57.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.mon.startnews24</string>
<key>bundle-version</key>
<string>1.0.1</string>
<key>kindsoft</key>
<string>software</string>
<key>title</key>
<string>startnews24</string>
</dict>
</dict>
</array>
</dict>
</plist>

10 / 22« 先頭...89101112...20...最後 »