AFMultipartFormData使用JSON

AFNetworking處理上傳檔案時,用來組合request參數的AFMultipartFormData,除了能夾帶file,還可以包含其他request parameter,例如

AFHTTPRequestOperation *requestOperation = [manager POST:urlString parameters:nil constructingBodyWithBlock:^(id formData) {
        // 上傳圖片檔案
        UIImage *uploadImage =  [UIImage imageNamed:@"img_test.png"];
        NSData  *imageData = [CommonObject reduceImageSize:uploadImage];
        [formData appendPartWithFileData:imageData name:@"file" fileName:uploadFileName mimeType:@"text/plain"];
     
        // 也可以包含其他request parameter
[formData appendPartWithFormData:[@"Karen_Chang" dataUsingEncoding:NSUTF8StringEncoding]
                                    name:@"UserId"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", responseObject);
 } failure:^(AFHTTPRequestOperation *operation , NSError *error) {
        NSLog(@"%@", error);
}];

若request parameter是NSArray,NSArray又由一堆JSON Object組成,該如何append formData???

直接將NSArrayNSData
NSData *inputArray1 = [NSKeyedArchiver archivedDataWithRootObject:origionalArray];
[formData appendPartWithFormData:inputArray1 name:@"ArrayInput"];
會拋出如下錯誤
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x7ff24545fa50 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" 

後來改寫法如下,就成功了^^
NSError *writeError = nil;
NSData *inputArray2 =
[NSJSONSerialization dataWithJSONObject:origionalArray
                                options:NSJSONWritingPrettyPrinted
                                  error:&writeError];
[formData appendPartWithFormData:inputArray2 name:@"ArrayInput"];

AVPlayerViewController保留PlaybackControls並加上自訂touch event

AVPlayerViewController的showsPlaybackControls屬性預設為YES
但如果自訂Gesture如下,會因為預設的單擊本來就賦予給隱藏/顯示PlaybackControls而無效
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc]init];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ChangeStatus)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[playerVC.view addGestureRecognizer:tapGestureRecognizer];

如果想要達到單擊影片,能依照當下播放與否決定是否加上PLAY的遮罩圖示(如下圖)
則可以改寫touchesBegan event如下
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.playerVC.player.rate == 1.0) {
        // 播放中
    } else if (self.playerVC.player.rate == 0.0) {
        // 已暫停
    }
}