Have recently started adapting parts of my app to SwiftUI, and StoreKit2 is solving a lot of problems with its simplicity and ease of implementation.
I've hit an issue with the Privacy Policy and Terms of Service buttons/view that StoreKit2 supplies as default. In creating a basic SubscriptionView, of which sample code is commonly available, a call can be made to subscriptionStorePolicyDestination which (according to the docs), "Configures a view as the destination when someone chooses to view the corresponding policy in a subscription store view within this view."
Sadly, when implementing, text is misplaced and there is no title bar or action buttons...
So, in coding trial my solution, I create my subscription view and reference a new view for my Privacy Policy...
struct SubscriptionView: View {
let productIds = ["xx.xx.xx", "yy.yy.yy"]
var body: some View {
SubscriptionStoreView(productIDs: productIds)
.subscriptionStoreControlStyle(.automatic)
.subscriptionStorePolicyDestination(for: .privacyPolicy, destination: {
privacyPolicy
})
.onInAppPurchaseCompletion { product, result in
switch result {
case .success(.success(_)):
break
case .failure(_):
break
default:
break
}
}
}
}
@ViewBuilder
private var privacyPolicy: some View {
Text(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
)
}
My test privacyPolicy
view, when hitting the Privacy Policy button then displays a popup with no close button, and sample text that is not bounded to the enclosing view, whether portrait or landscape, as shown above.
Trying other subscriptionStorePolicyDestination calls (say, a URL) results in the same problem...
.subscriptionStorePolicyDestination(url: URL(string: "https://www.apple.com/legal/privacy/en-ww/")!, for: .privacyPolicy)
Being quite new to SwiftUI, I may be doing something wrong here and advice appreciated.
Should the enclosing view be titled, with close button with aligned text or web views? Or is more expected of the dev to create the view? If so, how?
Thanks
Same here. My workaround is wrapping the SubscriptionStoreView
with a GeometryReader { geometry in ... }
and limiting the privacyPolicy with .frame(maxWidth: geometry.size.width)