我正在尝试访问imagePickerController的NSURL返回值,但我不知道要为参数输入什么。甚至可以从这种方法中获取NSURL,如果没有,我还应该如何从imagePickerControlle获取NSURL?正如我一直在寻找的那样。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) -> NSURL {
let theURL: NSURL = (info[UIImagePickerControllerReferenceURL] as! NSURL)
let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
profilePicture.image = selectedImage
print("searchthis\(theURL)")
dismiss(animated: true, completion: nil)
return theURL
}
我想访问" theURL"这里:
@IBAction func signUpPressed(_ sender: AnyObject) {
let authInfo = AuthInfo()
authInfo.email = emailField.text!
authInfo.firstName = firstField.text!
authInfo.lastName = lastField.text!
authInfo.username = usernameField.text!
authInfo.password = passwordField.text!
authInfo.profilePicture = profilePicture.image
let url = imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo: ).theURL
let container = CKContainer.default()
let privateData = container.privateCloudDatabase
let record = CKRecord(recordType: "Authentication")
record.setValue(authInfo.email, forKey: "email")
record.setValue(authInfo.username, forKey: "username")
record.setValue(authInfo.firstName, forKey: "firstName")
record.setValue(authInfo.lastName, forKey: "lastName")
record.setValue(authInfo.password, forKey: "password")
record.setValue(authInfo.profilePicture, forKey: "profilePicture")
record.setValue(CKAsset(fileURL: ))
privateData.save(record, completionHandler: { record, error in
if error != nil {
print(error)
}
})
}
谢谢!
答案 0 :(得分:0)
您必须单独获取配置文件图像,并且必须将URL和图像保存在全局变量中。 像:
//first register your view controller for image picker delegates
@IBAction func profilePickBtnPressed(_ sender: AnyObject) {
let _mediaPicker = UIImagePickerController()
_mediaPicker.delegate = self
_mediaPicker.mediaTypes = ["public.image" as String]
_mediaPicker.allowsEditing = false
_mediaPicker.sourceType = .Camera
self.presentViewController(_mediaPicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
//BTW, this is delegate method of picker controller
globalURL = (info[UIImagePickerControllerReferenceURL] as! NSURL)
globalImage = info[UIImagePickerControllerOriginalImage] as! UIImage
profilePicture.image = selectedImage
print("searchthis\(theURL)")
dismiss(animated: true, completion: nil)
}
然后在此函数中使用这些全局保存的值:
@IBAction func signUpPressed(_ sender: AnyObject) {
let authInfo = AuthInfo()
...
authInfo.profilePicture = globalImage
let url = globalURL
let container = CKContainer.default()
...
}