Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在signUpInBackgroundWithBlock期间将配置文件图像上载到parse.com时出现问题_Ios_Swift_Parse Platform_Uiimage - Fatal编程技术网

Ios 在signUpInBackgroundWithBlock期间将配置文件图像上载到parse.com时出现问题

Ios 在signUpInBackgroundWithBlock期间将配置文件图像上载到parse.com时出现问题,ios,swift,parse-platform,uiimage,Ios,Swift,Parse Platform,Uiimage,我正在使用下面的代码使用用户名、密码和个人资料图片注册用户 func createUserwithAllFields() { let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6) //let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6) let profileImageFile = PFFile(d

我正在使用下面的代码使用用户名、密码和个人资料图片注册用户

func createUserwithAllFields() {
    let profileImageData =  UIImageJPEGRepresentation(profileAvatar.image, 0.6)
    //let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6)
    let profileImageFile = PFFile(data: profileImageData)


    if tv_username.text != ""
        && tv_password.text != ""
    {

        var user = PFUser()

        user.username = tv_username.text
        user.password = tv_password.text

        user["profileImage"] = profileImageFile

        user.signUpInBackgroundWithBlock({ (success, error) -> Void in
            if error == nil {

                //if SignUp is successful

                let installation = PFInstallation.currentInstallation()
                installation["user"] = user
                installation.saveInBackgroundWithBlock(nil)

                //self.showChatOverview()

                self.goToMainScreen()

            } else {

            }
        })

    }else{

    }
}
当我在parse.com上查看他
User
类时,有一个文件被上传(见下面的屏幕截图)

虽然有一个文件,但当我点击并下载它时,我打开它会发现一个空白(即白色)图像

profiler avatar
是ViewController中的一个
UIImageView
,它确实指向一个有效的图像,因为我在运行应用程序时可以看到它

<>这是我看到的空白图像:

在解析中,您需要首先保存用户,然后在保存图像后,我修改您的代码以完成以下操作:

func createUserwithAllFields() {
    let profileImageData =  UIImageJPEGRepresentation(profileAvatar.image, 0.6)
    let profileImageFile = PFFile(data: profileImageData)
    if tv_username.text != "" && tv_password.text != "" {
        var user = PFUser()
        user.username = tv_username.text
        user.password = tv_password.text

        user.signUpInBackgroundWithBlock({ (success, error) -> Void in
            if error == nil {
                /println("SignUp is successful")
                 user["profileImage"] = profileImageFile
                 user.signUpInBackgroundWithBlock({ (success, error) -> Void in
                     if error == nil {
                         println("Image Saved")
                     } else {
                         println("Fail to Save Image")
                     }
                )}
            } else {
                println("Fail to Sign up")
            }
        })
    }else{
        println("Invalid username and password")
    }
}

我试过了。如果尝试修改代码,则不会上载
profileImage
字段的文件。您的图像有多大?10 kB(图像大小)我想知道是否不允许您在用户表中创建图像,我正在尝试在Parse.com文档中查找一些内容,但运气不好!所以我找到了一些东西-我尝试了一个
*.jpg
图像,效果非常好。我之前试过一个“*.png”,显然这就是问题所在。不知道为什么。