I’m new to programming and iOS improvement and I’m attempting to construct an onboarding circulation for my app.
I wish to ask the person for permission so as to add photos of their photograph library after they use the app for the primary time.
I’ve a working code, however it is just fired when the person needs to avoid wasting their first picture and I wish to transfer the authorization request to the onboarding circulation with out saving any photos.
I do not want entry to see the opposite photos of their photograph library, simply permission so as to add new photos.
I wish to keep away from directing the person out of my app to the settings, as a result of that is the primary time they are going to be prompted for authorization.
That is the present working code, however for this code I would like a picture to be saved:
import UIKit
import PhotosUI
if picture != nil {
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: picture!)}, completionHandler: {success, error in
})
}
I attempted to change it for the onboarding circulation to keep away from saving a picture on the time of the permission request:
In UIView setup:
button.addTarget(self, motion: #selector(askAuthorization), for: .touchUpInside)
Outdoors of UIView setup:
@objc func askAuthorization() async {
let standing = PHPhotoLibrary.authorizationStatus(for: .addOnly)
// If the system hasn't decided the person's authorization standing, explicitly immediate them for approval.
if standing == .notDetermined {
await PHPhotoLibrary.requestAuthorization(for: .addOnly)
}
}
The authorization request pops up appropriately, however the app crashes on account of reminiscence points instantly after deciding on OK.