Archive for category iPhone

[iPhone]ソフトバンクでテザリングを有効にする


【注意】
iPhone OS 3.1で対策が行われ、この方法でテザリングを有効にすることが出来なくなりました。3.1でのテザリングは別の方法でやれるか検証しているのでまたこのブログをチェックするかTwitterでもフォローしてみてください。

3.1.2での手順はこちら(要脱獄)

テザリングというのはiPhone 3.0からの機能でiPhoneの通信機能を、パソコンなどから使えるようにするというものです。

iPhoneがあれば、iPhoneがルーターになりノートパソコンがあればどこでもインターネットができるということです。

しかし、ソフトバンクはそれを許可していないために使うことが出来ません。
iPhone3.0で、ジェイルブレークしなくてもテザリングに成功ましたのでその方法をまとめました。

速度は2Mbps程でるのでADSLみたいなかんじです。もうすぐでるiPhone 3GSだと7Mでるらしいですが。
(名古屋市内の自宅だと5Mbpsくらいでした)

やりたい人は自己責任で行ってください。何が起こっても私は責任を負えません。

以下のコードを
ファイル名:jp_softbank_iphonepacket_usims.mobileconfig
UTF8で保存して、添付ファイルでiPhone宛にメールで送るか、このページをiPhoneでアクセスして上のリンクをクリックするだけでOKです。

<?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>PayloadContent</key>
<array>
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>DefaultsData</key>
<dict>
<key>apns</key>
<array>
<dict>
<key>apn</key>
<string>smile.world</string>
<key>password</key>
<string>so2t3k3m2a</string>
<key>type-mask</key>
<integer>-2</integer>
<key>username</key>
<string>dna1trop</string>
ma</dict>
</array>
</dict>
<key>DefaultsDomainName</key>
<string>com.apple.managedCarrier</string>
</dict>
</array>
<key>PayloadDescription</key>
<string>Provides customization of carrier Access Point Name.</string>
<key>PayloadDisplayName</key>
<string>Advanced Settings</string>
<key>PayloadIdentifier</key>
<string>jp.softbankusims.profile.apn</string>
<key>PayloadOrganization</key>
<string>Softbank iPhone Packet Flat usim Japan</string>
<key>PayloadType</key>
<string>com.apple.apn.managed</string>
<key>PayloadUUID</key>
<string>AA4E4364-57EA-4EFE-91EA-D33EEBD81446</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</array>
<key>PayloadDescription</key>
<string>Softbank iPhone Packet Flat usim Japan - BenM.at</string>
<key>PayloadDisplayName</key>
<string>JP Softbank iPhone Packet Flat usim</string>
<key>PayloadIdentifier</key>
<string>jp.softbankusims.profile</string>
<key>PayloadOrganization</key>
<string>Softbank iPhone Packet Flat usim Japan</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>A882C0D6-1D18-42EC-9013-3F466A0A4291</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>

添付ファイル

添付ファイルをタップしてプロファイルをインストールする
プロファイルのインストール

環境設定からテザリングを有効にする

テザリングを有効にする
テザリングを有効にする

USB接続かBluetooth接続するとネットワークを認識するのて適用を押す
ネットワークを認識

テザリングが成功すると画面上部が青く光る
テザリング成功

Bookmark and Share

56 Comments

[iPhone]Debug Log用マクロ

xcodeでデバッグログを出力するときは普通NSLog()を使うのだが、これが結構重たい上、Releaseビルドでも出力されてしまうのでどうしたもんかと思っていたのだが、設定とマクロでうまくできるのがわかったのでメモ。

プロジェクトの設定を開く。構成でDebugを選択
左下のボタンを押してユーザー定義の設定を追加
GCC_PREPROCESSOR_DEFINITIONSを追加し、DEBUGを設定する
e38394e382afe38381e383a3-4

以下のマクロを、インクルードされるヘッダに定義する

#ifdef DEBUG
#   define TRACE(fmt, ...) NSLog((@"%s(%d) " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define TRACE(...)
#endif

ログを出力したい場所で以下の様に使う

TRACE("startDownload genre=%@",genreId);

出力結果
2009-04-16 18:57:18.519 Beatport[14249:20b] -[TrackListViewController startDownload:](76) startDownload genre=10

「オブジェクト名 メソッド名(行番号) ログ」
という形式で出力される。マクロを以下の様に変更するにすると、ファイル名(行番号)で出力される

#   define TRACE(fmt, ...) NSLog((@"%s(%d) " fmt), __FILE__, __LINE__, ##__VA_ARGS__);

出力結果
2009-04-16 19:01:19.699 Beatport[14317:20b] 2009-04-16 19:01:45.633 Beatport[14317:20b] /Users/takatronix/Documents/Beatport/Classes/TrackListViewController.m(76) startDownload genre=10

tAkatronixおすすめのiPhone開発本

iPhone デベロッパーズ クックブック
Erica Sadun
ソフトバンククリエイティブ
売り上げランキング: 84906
詳解 Objective-C 2.0
詳解 Objective-C 2.0
posted with amazlet at 10.01.31
荻原 剛志
ソフトバンククリエイティブ
売り上げランキング: 4163
iPhoneプログラミングUIKit詳解リファレンス
所 友太
リックテレコム
売り上げランキング: 3089
iPhone Core Audioプログラミング
永野 哲久
ソフトバンククリエイティブ
売り上げランキング: 22615
Bookmark and Share

No Comments

[iPhone]ActionSheetでCancelボタンが効かない問題

現在作成中のiPhoneアプリでダウンロード中の状態表示をするようにしてみた。

ActionSheetを作成して、それにUIProgressViewを貼り付けるまでは簡単だった。

オブジェクトをコントローラクラスに追加し、

	UIActionSheet	*actionSheet;
	UIProgressView *progressBar;
	UILabel			*progressLabel;

ViewDidLoadでActionSheetを作成

-(void)createActionSheet {

	if(!actionSheet) {
		actionSheet = [[UIActionSheet alloc] initWithTitle:@"Please wait...\n\n\n\n"
												  delegate:self
										 cancelButtonTitle:NSLocalizedString(@"Cancel",nil)
									destructiveButtonTitle:nil
										 otherButtonTitles:nil];

		actionSheet.actionSheetStyle = UIBarStyleBlackTranslucent;

	}
	if(!progressBar) {

		progressBar = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 40.0f, 260.0f, 90.0f)];
		progressBar.progressViewStyle = UIProgressViewStyleDefault;
		progressBar.progress = 0.0f;
		[actionSheet addSubview:progressBar];

		progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 50.0f, 240.0f, 20.0f)];
		progressLabel.backgroundColor = [UIColor clearColor];
		progressLabel.textColor = [UIColor whiteColor];
		progressLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
		progressLabel.text = NSLocalizedString(@"Downloading...", nil);

		[actionSheet addSubview:progressLabel];
	}

}

ダウンロードの開始のタイミングでActionSheetを作成

- (IBAction)startDownload:(NSString*)genreId {
	downloadedContentLength = 0;
	progressBar.progress = 0;
	progressLabel.text = NSLocalizedString(@"Downloading", nil);
	[actionSheet showInView:self.view];
//  以下略

ダウンロードの処理の途中にUIProgressViewを更新してやると完成
img1

ここまではサンプルコード通りにやれば簡単だった。

しかしどうやってもキャンセルボタンが効かない。

ViewDidLoadでActionSheetを表示させるとキャンセルボタンが効くが画面の真ん中に表示されてしまう。

ActionSheetのボタンがキャンセルボタン一つだとうまくいかないが、ボタンを増やすとキャンセルが効く・・・。???
showInViewを使わずに、showFromTabBarを使うと上からアクションシートが降りてくるがキャンセルボタンが効く。

ググると同じような問題がたくさんあって、うまく動かないので別のスレッドを使えととかかいてある。

初期化のタイミングを変えたりスレッド化したり一晩さんざん悩んだあげく、よくよく調べてみるとSDK2.2のバグらしい。

んで、いろいろ調べた結果一番エレガントな回避コードは

こいつを

[actionSheet showInView:self.view];

こうしてやることだった。

[actionSheet showInView:self.view.window];

img2

tAkatronixおすすめのiPhone開発本

iPhone デベロッパーズ クックブック
Erica Sadun
ソフトバンククリエイティブ
売り上げランキング: 84906
詳解 Objective-C 2.0
詳解 Objective-C 2.0
posted with amazlet at 10.01.31
荻原 剛志
ソフトバンククリエイティブ
売り上げランキング: 4163
iPhoneプログラミングUIKit詳解リファレンス
所 友太
リックテレコム
売り上げランキング: 3089
iPhone Core Audioプログラミング
永野 哲久
ソフトバンククリエイティブ
売り上げランキング: 22615
Bookmark and Share

No Comments

[iPhone]プロパティリストを読み込む NSDictionary


UITableViewにbeatportのジャンルのリストを表示するのに一番スマートな方法を模索していていい感じにやる方法がわかったのでメモ。

ベタにコードに書かずにプロパティリストエディタでgenre.plistを作成しリソースに追加する。

plist

テーブルビューに表示する名称の配列とジャンルのデータを定義する

@interface RootViewController : UITableViewController {
NSArray*		names;
NSDictionary *dictGenre;
}
@property (retain) NSArray*		names;
@property (retain) NSDictionary* dictGenre;

プロパティリストファイルをNSDictionaryクラスに読み込み、キー一覧をソートしてNSArrayオブジェクトへ展開する迄

//		Genre.plistの読み込み
NSString *pathGenre = [[NSBundle mainBundle] pathForResource:@"Genre" ofType:@"plist"];

//		RootViewControllerを取得
RootViewController* rootViewController;
rootViewController = (RootViewController*)navigationController.topViewController;

rootViewController.title = @"Grenres";
rootViewController.dictGenre = [NSDictionary dictionaryWithContentsOfFile:pathGenre];

//	NSDicronayのkeyを配列に取り出してソート
NSArray *sortedArray =[[rootViewController.dictGenre allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
rootViewController.names = sortedArray;

UITableViewのセル描写のコールバックでソートしたジャンル名を表示してやる。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [names count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
  	cell.text = [names objectAtIndex:indexPath.row];
    return cell;
}

ウホッ
grenre
tAkatronixおすすめのiPhone開発本

iPhone デベロッパーズ クックブック
Erica Sadun
ソフトバンククリエイティブ
売り上げランキング: 84906
詳解 Objective-C 2.0
詳解 Objective-C 2.0
posted with amazlet at 10.01.31
荻原 剛志
ソフトバンククリエイティブ
売り上げランキング: 4163
iPhoneプログラミングUIKit詳解リファレンス
所 友太
リックテレコム
売り上げランキング: 3089
iPhone Core Audioプログラミング
永野 哲久
ソフトバンククリエイティブ
売り上げランキング: 22615
Bookmark and Share

1 Comment

[iPhone]UIImageViewにUILableで動く時刻を貼り付ける


ぐるぐる動かしているイメージ(UIImageView)に動く時計の文字列を貼り付けるのをどうやって実現するかでなやんだのだが、UIImageViewにUILabelを貼り付けたらどうだろうと思ってやってみたらうまくいった。

InterfaceBuilderだとUIImageViewのSubViewとして貼り付けることができなかったので、このようにUILabel を作成し、UIImageView* bImageのサブビューとして貼り付けた。

UILabel* timeLabel;
CGSize szImage = bImage.bounds.size;
timeLabel = [[[UILabel alloc] initWithFrame: CGRectMake(5,160,szImage.width,170)] autorelease];
timeLabel.font = [UIFont boldSystemFontOfSize:15.0];
[bImage addSubview:timeLabel];
timeLabel.textColor = [UIColor whiteColor];			//	文字色白
timeLabel.backgroundColor = [UIColor clearColor];	//	背景透明
timeLabel.textAlignment = UITextAlignmentCenter;	//	センタリング

UIImageを回転させるとUILabelも同じように回転する。
MFCのCWndクラスとは比べものにならないくらい高機能だな。時代の変化を感じるw。
img_00041

時刻文字列の作成はタイマーのコールバックで以下のようにやった。

NSDate *date = [NSDate date];		//	現在の日付を得る
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY/MM/dd kk:mm:ss"];
NSString* strTime = [dateFormatter stringFromDate:date];
timeLabel.text = strTime;

img_00061

ぐーるぐるまわったり拡大しても時刻もスムースに同期して動くね。

tAkatronixおすすめのiPhone開発本

iPhone デベロッパーズ クックブック
Erica Sadun
ソフトバンククリエイティブ
売り上げランキング: 84906
詳解 Objective-C 2.0
詳解 Objective-C 2.0
posted with amazlet at 10.01.31
荻原 剛志
ソフトバンククリエイティブ
売り上げランキング: 4163
iPhoneプログラミングUIKit詳解リファレンス
所 友太
リックテレコム
売り上げランキング: 3089
iPhone Core Audioプログラミング
永野 哲久
ソフトバンククリエイティブ
売り上げランキング: 22615
Bookmark and Share

No Comments