将用户照片上传到Parse Swift 4

时间:2018-10-08 17:05:17

标签: swift parsing xcode9.4

我终于弄清楚了我遇到的问题(显然我不是唯一一个有this问题的人。)

我不断收到此错误:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

为解决该问题,我做了以下事情:

1)添加导入照片

2)将键“ NSPhotoLibraryUsageDescription ”添加到您的info.plist中,类型为“ 字符串”,而值=“ $(PRODUCTNAME)使用照片

3)添加请求授权功能:

func imagePickerController(_ picker: UIImagePickerController, 
didFinishPickingMediaWithInfo info: [String : Any]) {


    PHPhotoLibrary.requestAuthorization({ status in
        switch status {
        case .authorized:
            print("PHAuthorizationStatusAuthorized")
        case .denied:
            print("PHAuthorizationStatusDenied")
        case .notDetermined:
            print("PHAuthorizationStatusNotDetermined")
        case .restricted:
            print("PHAuthorizationStatusRestricted")
        default:
            break
        }
    })
    // added "NSPhotoLibraryUsageDescription" to plist

4)使用this示例上传到解析服务器。注意:OP忘记添加CGfloat,即let imageData = UIImageJPEGRepresentation(image, 0.5)

5)产品>方案>编辑方案>环境变量OS_ACTIVITY_MODE:禁用

0 个答案:

没有答案