アプリ内でのフォームの分割表示

https://developer.apple.com/jp/documentation/ViewPG_iPhoneOS.pdf

 

【Swift】UISplitViewControllerの使い方。画面遷移(マスター部とディテーブル部) | はじはじアプリ体験記

 

iOS8から変更になったUISplitViewControllerについて調べてみた - Qiita

 

ポップオーバーについて

Using the PopoverView in iPad App Development - mobiForge

UIPopoverControllerを使ってみる : てるてる坊主

UIPopoverController

[XCODE] iPad専用のPopOverControllerを使ってみた - YoheiM .NET

ios-demo/iPad_PopoverView at master · cokecoffe/ios-demo · GitHub

 

Popoverの2つの実装方法を比較する - Qiita

Popoverの実装方法に関して、従来使っていたUIPopoverControllerクラスがiOS9で廃止予定とされました。

GitHub - hsylife/HowToDisplayPopover: To compare the two ways how to implement popover

 

Swiftでテキストフィールドにピッカーを設定しリスト選択する(コンボボックス的な) - Qiita

NSComboBox は iosでは使用不可

UIPickerView を使う必要がある

UITableViewのイベントが正しく動かない

 

UITableView がタップされた時のイベントdidSelectRowAtIndexPath で UIAlertController 関連のイベントが正しく動作しなかった。

dispatch_after 、dispatch_async などから、別スレッドを起こして、を使うパターンをためしたけど、うまくいかない。

自分は、タイマーを使ったらうまくできた。

 

//TableViewがタップされた時のイベント
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    // タイマーを作成してスタート
    NSTimer *tm =    [NSTimer    scheduledTimerWithTimeInterval:0.01f
                                                         target:self
                                                       selector:@selector(func1:)
                                                       userInfo:nil
                                                        repeats:NO
                      ];
}

-(void) func1:(NSTimer*)timer{
    NSIndexPath* indexpath = [self.tableView indexPathForSelectedRow];
    NSString* message =[NSString stringWithFormat:@"%zd" ,indexpath.row ];
}    

 

 

 


参考

スレッドプログライミング
https://developer.apple.com/jp/documentation/Multithreading.pdf

ファイル出力(追記 append)

 

    
    NSString* folder = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)[0];
    NSString* filePath = [NSString stringWithFormat:@"%@/out.txt",folder ];


//ファイル名の取り出し NSString* folderName = [filePath lastPathComponent]; //ファル名の取り出し NSString* FileName = [filePath stringByDeletingLastPathComponent]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError* error; //ファイルの有無の確認 BOOL result = [fileManager fileExistsAtPath:filePath]; if(!result){ BOOL success; //フォルダを作成 success = [fileManager createDirectoryAtPath:folderName withIntermediateDirectories:YES attributes:nil error:&error]; //ゼロバイトのファイルを作成 success = [fileManager createFileAtPath:filePath contents:nil attributes:nil]; } //ファイルの追記 NSString* rec = @"aaaaaaaaaaaaaaaa\n"; @synchronized (self) { NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:filePath]; [fh seekToEndOfFile]; NSData *data = [rec dataUsingEncoding:NSUTF8StringEncoding]; [fh writeData:data]; [fh closeFile]; }

 

参考

http://www.deftrash.com/blog/archives/2010/10/iphone_file_append.html

http://buchi.hatenablog.com/entry/2014/09/08/155919

 

UIAlertController 同期処理

UIAlertController を使用した際の同期処理がうまくできない。

セマホを使っても、元々メインスレッド上で処理されているらしく、wait待ちすると、ポップアップすら止まってしまう。

どうも VBでいうところの、DoEvents方式しかないようだ。

 

    ....
    [view presentViewController:alertController animated:YES completion:nil];

    while (! finished) {
        // 0.5秒間隔で、finishedしているか、確認しがなら待地合わせる。
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
    }

NSError の使い方

呼ばれる側

+ (BOOL)testMethod error:(NSError**)error{

    __block NSError*  responsError = nil;
    __block NSInteger httpStatus = 0;

    NSURLSessionDataTask* task = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    
        responsError =error;
        httpStatus = ((NSHTTPURLResponse* )response).statusCode;
    }];


    if (responsError){
        *error =responsError;
        return NO;
        
    }else  if (httpStatus == 200){
        error=nil;
        return YES;
    }else{
        NSDictionary *errorUserInfo = @{NSLocalizedDescriptionKey: @"upLoadで失敗しました",
                                        NSLocalizedFailureReasonErrorKey: @"HTTPコードが200以外"};
        
        *error = [[NSError alloc] initWithDomain:@"testMethod" code:httpStatus userInfo:errorUserInfo];
        return NO;
    }

}

呼ぶ側

   NSError* error = nil;
 
   BOOL rtn =  [testMethod error:&error];
   
    if (! rtn) {
        NSLog(@"%@",error);
        NSLog(@"%@",error.localizedDescription);
        NSLog(@"%@",error.localizedFailureReason);
    } 

 

NSLocalizedDescriptionKey で設定した内容は、error.localizedDescriptionで取得できる。

NSLocalizedFailureReasonErrorKey で設定した内容は、error.localizedFailureReason で取得できる。

 

アイコンバッチ

アイコンバッチを表示する方法を検索すると以下の用法が表示される 

[UIApplication sharedApplication].applicationIconBadgeNumber = 5;

 この通りやっても、表示されなかった。iOS9からは通知に関する設定を行わないといけなくなったようだ。


IOS9からは、ユーザーの認証が必要になったみただ。

下記のコードをAppDelegate.m 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 配下に実装する必要がある。

UIUserNotificationType types = UIUserNotificationTypeBadge;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[application registerUserNotificationSettings:settings];

 初回実行時に、「〜( アプリ名)〜は通知を送信します

よろしいですか?」が表示されるようになる。許可する/しない の設定は、

後から変更できる。設定→通知→該当のアプリ。通知を許可をオン、Appアイコンにバッチを表示をオン。

これで、アイコンにバッチが表示されるようにはなったけど、

iOS10からは、非推奨のメソッドになっている!?


 iOS10でコンパイルエラーが出ないように書き直してみた。こんなのでいいのかなぁ?

AppDelegate.m

 

#import <UserNotifications/UserNotifications.h>   を冒頭で追加する必要あり



-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (granted){ NSLog(@"承認された"); }else{ NSLog(@"承認されなかった"); } }]; return YES; }

この例の場合、アイコンバッチだけの確認になっています。

[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge + 

UNAuthorizationOptionAlert

)  とすれば、複数の条件が申請できるみたい。

 

granted には、許可に認否結果が渡ってくる。

初回許可しても、後々設定から不許可にした場合も、grantedには NOが渡ってくる。


バッチの数量はいつくまで、表示できるのか?

6桁まではそのまま表示される。

7桁以上の場合、中間の桁が ... 表示となり省略されるようだ。

f:id:nabe_shodai:20170619000247p:plain  f:id:nabe_shodai:20170619000300p:plain

 


参考

iOS9でバッジが表示されない時の対処法
https://trueman-developer.blogspot.jp/2015/12/ios9.html

 

iOS User Notifications framework」シリーズまとめhttp://dev.classmethod.jp/smartphone/iphone/user-notifications-framework-16/

 

iOS 10 User Notifications Framework実装まとめhttp://qiita.com/mshrwtnb/items/3135e931eedc97479bb5