Category Archives: IOS

「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>

iOSでファイルをアップロードするプログラム

コード下記:
#pragma mark
//アップロード開始
-(void)uploadingStart:(NSNotification *)notification
{
NSLog(@”start”);
}

//アップロード
-(void)uploadingProgress:(NSNotification *)notification
{
NSString *progress = notification.object;
progressView.progress = [progress floatValue];
NSLog(@”progress = %@”,progress);
}

//アップロード完了
-(void)uploadingFinish:(NSNotification *)notification
{
NSLog(@”finish”);
}

Objective-Cの文字列(NSString)の基本概念とよく利用方法

1.文字列の定数を作成

NSString *string1=@”これは文字列定数です”;
//空の文字列を作成
NSString *string2=[[NSString alloc]init];
NSString *string3=[NSString string];
/
NSString *string4=[[NSString alloc]initWithString:@”素早く文字列を作成”];
NSString *string5=[NSString stringWithString:@”素早く文字列を作成”];

//フォーマット文字列を作成
int number=2;
NSString *string6=[[NSString alloc]initWithFormat:@”%d”,number];
NSString *string7=[NSString stringWithFormat:@”%d”,number];

2.文字列の内容を比較

NSString *string6=[[NSString alloc]initWithFormat:@”%d”,number];
NSString *string7=[NSString stringWithFormat:@”%d”,number];
NSLog(@”%@,%@,%@,%@,%@,%@,%@”,string1,string2,string3,string4,string5,string6,string7);
//2つの文字列が等しいかどうかを比較
if([string6 isEqualToString:string7])
{
NSLog(@”同じコンテンツ”);
}else{
NSLog(@”異なるコンテンツ”);
}

3.2つの文字列を比較して同一オブジェクトかどうかを判断

NSString *string8=[NSString stringWithString:@”startnews24″];
NSString *string9=[NSString stringWithString:@”startnews24″];

if([string8 isEqualToString:string9])

{

NSLog(@”同じコンテンツ”);

}else{

NSLog(@”異なるコンテンツ”);
}
if(string8==string9){
NSLog(@”同じオブジェクト”);
}else {
NSLog(@”異なるオブジェクト”);
}

4. 文字列の大きさを比較
//文字列の大きさを比較
NSString *string10=[[NSString alloc]initWithString:@”startnews24″];
NSString *string11=[[NSString alloc]initWithString:@”startnews_24″];
NSComparisonResult result=[string10 caseInsensitiveCompare:string11];
NSLog(@”%ld”,result); //-1昇順
5.文字列の長さを求める
NSString *string12=[[NSString alloc]initWithString:@”arkgame.com”];
NSLog(@”string12の長さ:%ld”,[string12 length]);

6.文字列を変換

NSString *string13=[[NSString alloc]initWithString:@”welcome_arkgame.com”];
NSLog(@”upper %@”,[string13 uppercaseString]);
NSLog(@”lower %@”,[string13 lowercaseString]);
NSLog(@”capitalized %@”,[string13 capitalizedString]);
7.文字列から基本データのタイプに変換
NSString *string14=[[NSString alloc]initWithString:@”3.14″];
NSLog(@”%.2f\n”,[string14 floatValue]);

8.文字列から配列に変換

NSString *string15=[[NSString alloc]initWithString:@”www startnews 24 .com”];
NSArray *array=[string15 componentsSeparatedByString:@””];
NSLog(@”%@\n”,array);

9.文字列を切り取る

NSString *string16=@”startnews24_view”;
NSLog(@”%@”,[string16 substringToIndex:2]);
NSLog(@”%@”,[string16 substringFromIndex:2]);
NSRange range;
range.location=2;
range.length=3;
NSLog(@”%@”,[string16 substringWithRange:range]);
10.文字列を連結

NSString *string17=@”www.”;
NSString *string18=@”arkgame.com”;
NSString *appString=[[NSString alloc]initWithFormat:@”連結文字列:%@ and %@”,string17,string18];
NSString *appString2=[string17 stringByAppendingString:@”123″];
NSString *appstring3=[string17 stringByAppendingFormat:@”%@”,string18];
NSLog(@”%@,%@,%@”,appString,appString2,appstring3);

11.文字列の検索

NSString *link=@”arkgame.com-===soft opensource”;
NSRange range1=[link rangeOfString:@”soft”];
NSLog(@”%@”,NSStringFromRange(range1));
if(range1.location != NSNotFound)
{
NSLog(@”見つかった!”);
}

Objective-Cの中で可変文字列(NSMutableString)の良く利用方法

1.文字列を挿入
NSMutableString *string19=[[NSMutableString alloc]initWithFormat:@”startnews24_welcome”];
[string19 insertString:@”soft” atIndex:2];
NSLog(@”%@”,string19);

2.文字列を置換
[string19 replaceCharactersInRange:NSMakeRange(0, 3) withString:@”startnews24″];
NSLog(@”%@”,string19);

3.文字列を削除
[string19 deleteCharactersInRange:NSMakeRange(0, 3)];

 

 

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