I am on Xcode 16.2 and running a simulator for iOS 18.2. Previously, I was on Xcode 15.x and running iOS 17.4 sims. This problem did not occur for me on iOS 17.4. Sample code is as follows:
import SwiftUI
import PhotosUI
struct ContentView: View {
@StateObject var imagePicker2 = ImagePicker()
var body: some View {
ScrollView {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
.background(Color.orange)
.padding(.bottom, 75)
PhotosPicker(selection: $imagePicker2.imageSelection, matching: .images, photoLibrary: .shared()) {
Label("", systemImage: "photo")
}
.font(.system(size: 55))
.padding(.bottom, 55)
if let image = imagePicker2.image {
HStack {
image
.resizable()
.frame(width:75, height:75)
.scaledToFit()
.overlay(Rectangle().stroke(Color.teal, lineWidth: 2))
}
}
}
.padding()
}
}
}
import SwiftUI
import PhotosUI
@MainActor
class ImagePicker: ObservableObject {
@Published var unableToLoad: Bool = false
@Published var image: Image?
@Published var myUIImage: UIImage?
@Published var imageSelection: PhotosPickerItem? {
didSet {
unableToLoad = false
if let imageSelection {
//.. try to convert photosPickerItem imageSelection into a uiImage
Task {
try await setImage(from: imageSelection)
}
}
}
}
func setImage(from imageSelection: PhotosPickerItem?) async throws {
do {
if let data = try await imageSelection?.loadTransferable(type: Data.self) {
print("got image data")
if let uiImage = UIImage(data: data) {
print("converted to uiImage")
self.image = Image(uiImage: uiImage)
self.myUIImage = uiImage
}
}
} catch {
print(error.localizedDescription)
unableToLoad = true
}
}
}
The image loads on the UI but I get "[ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider" in the log every time I choose a new photo. So far, I haven't had an actual crash but others have indicated that depending on what they're doing code-wise, that some have crashed. Is this an iOS 18.x bug? Thoughts?
Post
Replies
Boosts
Views
Activity
I would like to implement in-app auto-renewing subscriptions to open up "Pro" options for my app if a user chooses to subscribe. The user would be able to choose from a monthly or yearly subscription version. I have looked at hours and hours of countless videos, documents, tutorials, Apple examples (Backyard Birds, etc.), and posts on all of this but I'm still not sure that I understand the correct way to do this via the "new" StoreKit 2 framework additions. From various WWDC videos, it would seem that it's now as simple as using SubscriptionStoreView and then utilizing the modifiers .onInAppPurchaseCompletion, .subscriptionStatusTask, and .manageSubscriptionsSheet. It sounded to me like everything, including purchases and verifying transactions, is handled automatically for auto-renewing subscriptions. When testing my app, I can bring up my store view with no problem and make purchases with the simulator. That being said however, I am finding it fairly difficult to understand exactly what I need to do in order to make this all work correctly. The following are questions that I need answered in order to proceed:
For in-app auto renewable subscriptions, should we just be using: SubscriptionStoreView, .onInAppPurchaseCompletion, .subscriptionStatusTask, and .manageSubscriptionSheet?
Does .subscriptionStatusTask automatically and continually check for subscription status changes so that views dependent on that status will know whether or not a user has a valid subscription?
Do I also need to set up a task when opening my app that checks for current entitlements?
Do I still need to explicitly verify transactions or devices?
What is supposed to happen with the logic flow? Is it suppose to be:
Check to see if user EVER had a subscription...
---- if NOT ->
present the paywall/store
---- else ->
present the manageSubscriptionSheet
Note: When I've tested variations of this, if the user didn't have a previous subscription at some point, the manageSubscriptionSheet will not be presented. It just "clocks" with a blank screen.
Sorry for so many questions. I submitted a code-level support request to get help with this but the email I received back said to just post in the forum. I'm hoping someone here can help. I have other questions also but I'll make a separate post for them. TIA.
My App sets up multiple local notifications via a loop based on a calendar date and time (calendar trigger). While everything else is working correctly with this, I cannot seem to get the badge number to increment properly. I tried setting this up via content.badge but what happens is...
User gets notification 1,2,3,4,5 and badge number gets set to 5 content.badge = self.counter
User then "clears" notifications 2 and 3 - and badge number is now 3 via my code (UIApplication.shared.applicationIconBadgeNumber - 1)
When the next notification (number 6) pops up, the badge number SHOULD show 4. It doesn't. It shows 6 because that's what was set via content.badge
What is the proper way to increment the badge number? I've looked at various posts here but they're for push notifications. Mine is for a local notifications. Can I set/update badge number WHEN a notification is actually delivered? ...Or does notification manager somehow handle this automatically?