return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
でEXC_BAD_ACCESSが発生した時はデバッグモードのゾンビオブジェクトを見たり
エラー時にログを発生される方法がある。
Zero4Racer PRO Developer's Blog
iOS 開発で、EXC_BAD_ACCESS とさよならするための6つのルール
http://www.zero4racer.com/blog/88
DJやったり、IPhoneアプリ開発やったり、、、
【iPhoneアプリ】EXC_BAD_ACCESSを解決する
http://dj32mitsu.blog.fc2.com/blog-entry-21.html
しかし今回コーディングをしているうちにどうしても解消できないエラーが発生した。
エラー内容はMain.mでのEXC_BAD_ACCESSだが、どうしても解消できない。
コードを1つ1つ検証してみた結果
main.m後に呼び出されるAppDelegate.mで呼び出されるはずの関数をコメントアウトしていた。
というのが原因だった。
間接的な原因はAppDelegateをいろいろと変更しているうちにおかしなクラスになってしまったようだ。
AppDelegateで行う処理はAppDelegateでないとできない処理だけにしてこう。
2015年2月17日火曜日
2015年2月3日火曜日
[iOS]setNavigationBarHiddenで座標frameがずれる
iOS7以降setNavigationBarHiddenを呼び出すとViewControllerのSubViewsが
UINavigationbarが消えた分y座標が変更される(-44.0移動する)
自動で変更したくない時は
self.automaticallyAdjustsScrollViewInsets = NO;を使用する
2015年2月2日月曜日
[iOS]iOS7以降のStatusbar、Navigationbar、Toolbarのメモ
//ProjectAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 8.0) {
//iOS8でtoolbar naigationbarの透過をオフにする
//iOS7ではsetTranslucentでBOOLを受け付けないのでクラッシュする
[[UINavigationBar appearance] setTranslucent:NO];
[[UIToolbar appearance] setTranslucent:NO];
}
return YES;
}
//ViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
isHidingStatusBar = YES;
//iOS7 ステータスバーの表示/非表示切り替え
//navigationBarHidden toolbarHiddenを呼び出した時にも呼ばれる
[self setNeedsStatusBarAppearanceUpdate];
//iOS7
self.navigationController.navigationBarHidden = YES;
self.navigationController.toolbarHidden = YES;
[self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController setNavigationBarHidden:NO];
[self.navigationController.toolbar setBarTintColor:[UIColor blackColor]];
[self.navigationController.toolbar setTintColor:[UIColor whiteColor]];
[self.navigationController.toolbar setTranslucent:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//[[[UIApplication sharedApplication] keyWindow] tintColor]は変更がない限りデフォルトカラー
[self.navigationController.navigationBar setBarTintColor:[[[UIApplication sharedApplication] keyWindow] tintColor]];
[self.navigationController.navigationBar setTintColor:[[[UIApplication sharedApplication] keyWindow] tintColor]];
[self.navigationController.toolbar setBarTintColor:[[[UIApplication sharedApplication] keyWindow] tintColor]];
[self.navigationController.toolbar setTintColor:[[[UIApplication sharedApplication] keyWindow] tintColor]];
}
//setNeedsStatusBarAppearanceUpdateで呼び出される
- (BOOL)prefersStatusBarHidden {
//ステータスバーの表示/非表示をBoolで指定
return isHidingStatusBar;
}
//setNeedsStatusBarAppearanceUpdateで呼び出される
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
//アニメーションの設定
return UIStatusBarAnimationFade;
}
2014年7月31日木曜日
[iOS]UIImageをリサイズする
+ (UIImage *)resize:(UIImage *)image rect:(CGRect)rect
{
UIGraphicsBeginImageContext(rect.size);
[image drawInRect:rect];
UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
UIGraphicsEndImageContext();
return resizedImage;
}
2014年7月29日火曜日
[iOS]ディスプレイと画像の比率を求める
- (float)getScale :(CGSize)displaySize :(CGSize)imageSize {
float scale = 0.0;
if (imageSize.height > displaySize.height) {
scale = displaySize.height / imageSize.height;
} else {
scale = imageSize.height / displaySize.height;
}
return scale;
}
2013年7月3日水曜日
[iOS]NSLogで文字化けする問題
//recvDictをエンコードして表示する
NSString *dictString = [NSString stringWithFormat:@"%@",recvDict];
NSString *encodeString = [NSString stringWithCString:
[dictString cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding];
NSLog(@"encodeString %@", encodeString);
2013年6月19日水曜日
[iOS]NSURLConnectionの証明書切れを回避する方法
// 証明書切れ回避
- (BOOL) connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
2013年6月12日水曜日
[iOS]UserDefaultsに保存する
FileOpenなどをしなくて良いので便利
// hogeDictを保存 [[NSUserDefaults standardUserDefaults] setObject:hogeDict forKey:@"hoge"]; // hogeDictを読み出し NSDictionary *hogeDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"hoge"];
2013年6月6日木曜日
[iOS] AVAudioPlayerでサウンドが再生されない
NSString *path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mp3"];
NSString *expandedPath = [path stringByExpandingTildeInPath];
NSURL *url = [NSURL fileURLWithPath:expandedPath];
NSError *error = nil;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (audioPlayer) {
[audioPlayer prepareToPlay];
[audioPlayer play];
} else
NSLog(@"error %@", error);
}
簡単なコードなのに音声が再生されず、シンボルエラーで落ちるという現象が発生した。
落ちている場所はinitWithContentsOfURLのところ。
pathを変えてみるなどしたが、全く受け付けなかった。
・原因
使用した"sample.mp3"にあったようで、"sample.wav"などにエンコードすると問題なく再生された。
私がエンコードのヘッダーなどは分からないので詳細は不明だが、
エンコーダーやファイルによってはiOSで再生できないものがあるらしい。
そういえばAndroidSDKにもMediaPlayer似た問題があったな。
サウンドがが途切れたり、再生が遅かったり、再生されなかったり、、、
サウンド関係は面倒臭がらずにOpenALを使用したほうが結果的に良いかも
2013/06/19 追記
OpenALでも再生できなかった。
ビルドクリーンをして、本体orシミュレーターからアプリを削除して、
project.xcworkspaceとxcuserdataを削除した後に、
ビルドせずにMACを再起動して、ビルドをしたら問題無く再生された。
2013年6月4日火曜日
[iOS]文字列をLocalizable.stringから取得する
タグ = 表示したい文字列のフォーマット
Localizable.string
"sample" = "サンプル";
コード上で取得する
タグ,コメントでコメントは省略可
NSLocalizedString(@"network_domain", nil)
Localizable.string
"sample" = "サンプル";
コード上で取得する
タグ,コメントでコメントは省略可
NSLocalizedString(@"network_domain", nil)
登録:
投稿 (Atom)