0

I have an UIAlertController that allows a user to add a name and description of their smart advice. I would now like for the UIAlertController to allow the user to upload an image from their camera roll. I don't have any database or coredata enabled (Do I need to?). Here is my UIAlertController:

    @IBAction func refreash(_ sender: AnyObject) {
      
        
        let alert = UIAlertController(title: "Add Smart Device", message: nil, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        
        alert.addTextField(configurationHandler: { textField in
            textField.placeholder = "Enter Name of the Smart Device Here"
        })
        
        alert.addTextField(configurationHandler: { textField in
            textField.placeholder = "Enter Desc of the Smart Device Here"
        })
        
        // I want something like alert.addImagePicker here
        
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
            
            if let name = alert.textFields?.first?.text,
               let desc = alert.textFields?[1].text {
                self.mySmartDeviceList.addSmartDevice(name: name, desc: desc, image: "robot.jpg")
                let indexPath = IndexPath (row: self.mySmartDeviceList.getCount() - 1, section: 0)
                self.cityTable.beginUpdates()
                self.cityTable.insertRows(at: [indexPath], with: .automatic)
                self.cityTable.endUpdates()

            }
        }))
        
        self.present(alert, animated: true)
        
        
        
    }

See how it says that the image is just "robot.jpg"? I want that to be the image that the user uploaded.

zzzz
  • 67
  • 8

1 Answers1

0

If your app allow user use offline, u need to use local database to save it by id,name, And save file in local by id, then upload those picture when online. I suggest do not save NSdata in CoreData.

Leo Chen
  • 327
  • 1
  • 8
  • Can you please explain your answer in more detail about why you not suggest NSData in CoreData. – Protocol Nov 08 '21 at 17:13
  • There is some dicuss. https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay For me, I don't want API send all picture data when Data Sync every time, so I only save path or ID in my table, create another API only for upload picture data, use it after changing picture. – Leo Chen Nov 10 '21 at 01:41