相应的调用方法变了参数

5.0上下,对应的调用方法变了参数,而且只要用了5.0事后的措施在低版本上无法运用,而用低版本对用的艺术,apple已经不提倡,会有警示出现

图片 1

可以接纳对“执行事件”捕捉,来直接的成就包容性

13865632,1366,768.jpg

 if ([self respondsToSelector:@selector(dismissViewControllerAnimated:animated:completion:)]) {
        [self dismissViewControllerAnimated:YES completion:nil];//5.0+
    }
    else
    {
        [self dismissModalViewControllerAnimated:YES];//4.3-
    }

明天写道必要接纳照片(可以拍照或然采纳图库的),不赘述,上代码
以此是点击事件
<code>
//提交选项
-(void)sendDataAction:(UIButton *) button{

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
            [self presentViewController:loginView animated:YES completion:nil];//5.0+
        }
        else
        {
            [self presentModalViewController:loginView animated:YES];//4.3-
        }

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];

 

}
//那里做个判断

参考出路:http://www.2cto.com/kf/201205/133560.html

  • (void)actionSheet:(UIActionSheet *)actionSheet
    clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    if (buttonIndex == 0) {
    [self toCameraPickingController];
    }
    else if (buttonIndex == 1) {
    [self toPhotoPickingController];
    }

}
//相机判断

  • (void)toCameraPickingController
    {
    if (![UIImagePickerController
    isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    NSLog(@”Error:没有水墨画设备”);
    }
    else {
    UIImagePickerController *cameraPicker = [[UIImagePickerController
    alloc] init];
    cameraPicker.delegate = self;
    cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([self
    respondsToSelector:@selector(presentViewController:animated:completion:)])
    {
    [self presentViewController:cameraPicker animated:YES
    completion:nil];
    }
    else {
    // [self presentModalViewController:cameraPicker
    animated:YES];这几个是找的demo里面的,这一个格局过时了,被上面的代表了
    [self presentViewController:cameraPicker animated:YES
    completion:nil];

      }
      [_sendDataButt setTitle:@"已上传" forState:UIControlStateNormal];
    

    }
    }
    //图库判断

  • (void)toPhotoPickingController
    {
    if (![UIImagePickerController
    isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
    NSLog(@”Error:无图片库”);
    }
    else {
    UIImagePickerController *photoPicker = [[UIImagePickerController
    alloc] init];
    photoPicker.delegate = self;
    photoPicker.sourceType =
    UIImagePickerControllerSourceTypePhotoLibrary;
    if ([self
    respondsToSelector:@selector(presentViewController:animated:completion:)])
    {
    [self presentViewController:photoPicker animated:YES
    completion:nil];
    }
    else {
    // [self presentModalViewController:photoPicker
    animated:YES];那几个是找的demo里面的,那些格局过时了,被上面的代表了
    [self presentViewController:photoPicker animated:YES
    completion:nil];
    }
    [_sendDataButt setTitle:@”已上传” forState:UIControlStateNormal];

    }
    }

pragma mark UIImagePickerControllerDelegate Methods

//图片接纳

  • (void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    if ([self
    respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
    {
    [picker dismissViewControllerAnimated:YES completion:nil];
    }
    else {
    //[picker
    dismissModalViewControllerAnimated:YES];这几个是找的demo里面的,这几个措施过时了,被上边的代表了
    [self dismissViewControllerAnimated:YES completion:nil];
    }
    UIImage *imagePicked = [info
    objectForKey:UIImagePickerControllerOriginalImage];
    _sendImage.image = imagePicked;
    }

pragma mark UIImagePickerControllerDelegate Cancel Methods

  • (void)imagePickerControllerDidCancel:(UIImagePickerController
    *)picker
    {
    //[picker
    dismissModalViewControllerAnimated:YES];这些是找的demo里面的,那一个办法过时了,被下边的替代了
    [self dismissViewControllerAnimated:YES completion:nil];
    }
    //设置一下显示器
  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

</code>

<code>
补给一下,指点参数上传

  • (void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    NSLog(@”图片选中”);
    //截取图片
    UIImage *image = [info
    objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.001);
    self.mv.portraitImageView.image = image;

    AFHTTPRequestOperationManager *manager =
    [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet
    setWithObjects:@”text/html”,@”text/plain”, nil nil];
    // 参数
    NSMutableDictionary *parameter = [NSMutableDictionary
    dictionary];
    parameter[@”token”] = “param….”;
    // 访问路径
    NSString *stringURL = [NSString
    stringWithFormat:@”%@%@”,HOSTURL,kUploadAvatar];

    [manager POST:stringURL parameters:parameter
    constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
    {
    // 上传文件
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @”yyyyMMddHHmmss”;
    NSString *str = [formatter stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@”%@.jpg”, str];

      [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/png"];  
    

    } success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
    NSLog(@”上传成功”);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@”上传错误”);
    }];
    }

</code>

图片 2

13865647,1366,768.jpg

相关文章