Post not yet marked as solved
Hello,Sometimes, this piece of code opens iPhone Settings (instead of app Settings)let url = URL(string: UIApplication.openSettingsURLString)
UIApplication.shared.open(url!, options: [:], completionHandler: nil)But other times, it opens app settings, as the documentation says.(I am using iPhone X and iOS 12)I think the reason is that when the app does not appear in the settings list (because it is the first time that app is exectured), then openURL does not know how to open app settings (because it does not exist) and opens iphone settings. To test that, create an app with those 2 lines of code. And remember to reset the simulator entirely to test the wrong case.Do you have or see the same problem?Thanks a lot.
Post not yet marked as solved
I created a small component using a Text and optionally an Image, inside an HStack. Then I apply padding and clipping using a Capsule shape.
Below you have the code and the results.
The problem I have is that I want to constraint the component in a way that the width is always equal or higher than its height. That is, a vertical capsule is not allowed, only an horizontal capsule or a circle.
I tried different approaches.
For example, measure the component size using Geometry reader. We can use the .measure modifier, which basically puts everything inside .background and applies a Geometry Reader, and moves the value up using Preference Keys.
Measure modifier:
swiftuirecipes.com/blog/getting-size-of-a-view-in-swiftui
But it does not work, looks like the HStack is returning zero, or causing issues.
In any case, I was told to avoid GeometryReader whenever possible.
What other approaches I could follow?
There must be a way playing with .background and .layoutPriority, butI don't know exactly how to do it.
Would be nice to have something like an .aspectRatio modifier where we can pass something like "1 or higher", but I have no idea about how to implement that.
Do you have any idea or suggestion? Thanks a lot.
[![enter image description here][1]][1]
struct ContentView: View {
var body: some View {
VStack(spacing: 20) {
Label(text: "2", showIcon: true)
Label(text: "99+", showIcon: true)
Label(text: "1", showIcon: false) // Case to fix
}
}
}
struct Label: View {
let text: String
let showIcon: Bool
var body: some View {
HStack {
if showIcon {
Image(systemName: "bolt")
.resizable()
.frame(width: 15, height: 15)
}
Text(text)
}
.padding(4)
.background(Color.red)
.clipShape(Capsule())
}
}
Post not yet marked as solved
Hello,Suddenly my distribution certificate disappeared, invalidating all my provisioning profiles.Is it possible to see a log or similar to know what happended?Will Xcocde delete a certificate if I activate the "Automatically manage signing" checkbox?Thanks.
Post not yet marked as solved
How do I detect a refund? (question about cancellation_date)
My system uses auto-renewal subscriptions.
After reading this document:
https://developer.apple.com/library/archive/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPT-HOW_DO_I_USE_THE_CANCELLATION_DATE_FIELD_
I am not sure about how to manage the refund scenario.
The docs say that I have to check cancellation_date field. But what I don’t know is WHEN I will receive that.
When the user requests a refund to apple and apple accepts it, will my app receive a new transaction in
func paymentQueue(_ queue: SKPaymentQueue,
updatedTransactions transactions: [SKPaymentTransaction])
the next time the user runs the app?
Or do I have to use polling (my server checks every day with apple server all subscribers) or use server-to-server notifications?
Thanks for clarification.
Post not yet marked as solved
Hello,
I would like to use “Billing Grace Period”
But there is a scenario I don’t know how to manage.
My app sends the receipt to my server, my server verifies the receipt with apple and then unlocks content.
I am not using server-to-server notifications, basically because I will only have an iPhone app, moreover, seems server-to-server adds more complexity and this is a small project.
The scenario I don’t know how to manage is this:
Imagine I activate the “Billing Grace Period”, then the user, after buying an auto-renewal subscription, cancels it. Because the expiry date in the server takes into consideration graceperiodexpiresdatems, the real expiry date is longer, but my server does not know that the subscription was cancelled, which means the user that cancelled the subscription will always enjoy the grace period.
I think in this case, when cancelling, the app does not receive any transaction or something like that From StoreKit that says that the subscription was cancelled. That is the issue.
In this document:
https://developer.apple.com/documentation/storekit/in-app_purchase/subscriptions_and_offers/reducing_involuntary_subscriber_churn?preferredLanguage=occ
I see:
“When implementing Billing Grace Period, use the verifyReceipt JSON response and server-to-server notifications. ”
So, I would say it is mandatory to use server-to-server notifications to implement “Billing Grace Period” properly. Am I right? Is it totally mandatory?
Thanks a lot.
Post not yet marked as solved
Hello,I'm creating a small app to log all the domains the iPhone uses.I use NEPacketTunnelProvider, creating a virtual interface and redirecting all DNS traffic there, which means I don't have to manage TCP flows, just extract DNS queries from IP packets, and managing UDP sessions, which is much easier than managing TCP flows.I also use NEOnDemandRuleConnect so my VPN is always connected.My app works fine and I can see how all the domains are logged properly and the user can see them. I also inject back the actual DNS responses and the network works properly (you can browse website and use apps)This is the problem I have: Sometimes, whem going to WiFi to cellular, from cellular to WiFi or airplain mode to Wifi/3G, I see how the VPN starts again (probably because NEOnDemandRuleConnect, which is what I want) but then I see that the network does not work. No websites are loaded. If I check the system console (filtering by process name, otherwise it is impossible to see anything), I see something I don't see when everything works fine:error 21:19:25.226644 +0100 Domain Checker Extension __nw_socket_service_writes_block_invoke sendmsg(fd 5, 40 bytes): [51] Network is unreachableerror 21:19:25.227015 +0100 Domain Checker Extension nw_endpoint_flow_prepare_output_frames Failing the write requests: [51] Network is unreachableSo, maybe I'm missing something but I cannot see it.The documentation is not very clear about how to implement fault tolerant VPNs/tunnels, although I saw this document that perhaps says something that could be used for that:https://developer.apple.com/documentation/networkextension/neprovider/1406740-defaultpathShould I create a KVO observer in order to start the tunnel again when the interface changes?Perhaps when "defaultPath" changes, I should reconnect, but, the problem is that my extension is not connected to anything.When going to airplane mode, 3G, WifI... I see how "defaultPath" changes, so perhaps that's what I'm missing.Do you have any idea about what I should do? Or what could I try to solve this?Thank you very much for your suggestions.
Post not yet marked as solved
Hello,I already spent a while with MeasurementFormatter but I don't find a way to format a distance (person's height) to something like "5 ft, 11 in"I can only get one unit, but not 2.I already tried LengthFormatter with isForPersonHeightUse, which works properly but only when the locale is US.I need to format the height using ft/in because that is used in the UK, despite the fact the system says metric system is used there.Is this possible?Thanks a lot.
Post not yet marked as solved
Hello,I have a view controller container. When I transition from the first child view controller (a simple view controller) to the second one that has a tabbar and navigation bar, it appears that the initial position of the tabbar and the navigation bar are not the as expected, they are slightly outside the screen. See the GIF and the code. Do you know how can I avoid that strange animation? Or the root of the problem. Thanks. dashboardCoordinator = DashboardCoordinator()
rootViewController.addChild(dashboardCoordinator!.rootViewController)
let fromVC = onboardingCoordinator!.rootViewController
let toVC = dashboardCoordinator!.rootViewController
fromVC.willMove(toParent: nil)
rootViewController.transition(from: fromVC,
to: toVC,
duration: 5,
options: .transitionCrossDissolve,
animations: nil,
completion: { [weak self] finished in
guard let self = self else { return }
fromVC.removeFromParent()
self.onboardingCoordinator = nil
toVC.didMove(toParent: self.rootViewController)
})Animated GIFhttps://i.stack.imgur.com/Qo5Mn.gifThanks a lot.
Post not yet marked as solved
Hello,What's the proper way to create whitelists when using Safari content blocker API?https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ContentBlocker.htmlImagine I have an adult content blocker like this one, but instead of 3 domains, 50000. (I already did it and it works)[ { "action": { "type": "block" }, "trigger": { "url-filter": ".*", "if-domain": ["*xvideos.com", "********.com", "****.com"] } }]How should I add a whitelist? Do I have to create a second blocker with other rules or do I have to modify my adult content blocker to remove the whitelisted domains programatically in real time, generate another JSON and reloading it?Thanks for suggestions.
Post not yet marked as solved
Hello,My tunnel works fine (NEPacketTunnelProvider), but when I change interface (from wifi to 3g or the other way), I have problems and very often it does not work. Note that my tunnel only logs DNS queries, there is no connection with an external server.My question is: Do I have to apply a special logic when the interface is changed?Perhaps I have to call setTunnelNetworkSettings every time the interface is changed, or maybe cancelTunnelWithError. Can anyone tell me about this? Apart from that, what´'s the proper way to know if the current interface changes? Is it listening defaultPath?Thanks a lot.
Post not yet marked as solved
Hello,I would like to achieve this in order to parse DNS datagrams:Set the system DNS to some private address, let's say A.Route A to tun interface.Parse the DNS request receivedHow do I create an instance of a TUN interface inside a subclass of NEPacketTunnelProvider? I don't understand that very well. Any clue?Thanks a lot.
Post not yet marked as solved
I want to apply a special logic to DNS requests. Basically, I want to use a custom REST web service (already available) to know the category of the domain (gambling, p0rn0graphy...) and block it if needed or continue with the original DNS request as normal if the domain category is OK.THe context is to protect children from harful content, tracking the websites they want to visit, blocking some of them depending on categories (gambling, adult_content...) and a custom list created by their parents.I believe this is technically possible because we have apps like Charles Proxy that controls entirely the network, capturing every single packet.I think I have to use NETunnelProviderManager and create a tun device. DNS requests go to this tun device, that applies my logic.What I don't see is the big picture. Can you explain to me that?Do I have to create a proxy (it seems charles creates one locally)?Do I have to create a tunnel server?I don't want to modify TCP packets, maintain connections or modify UPD datagrams (except the ones related to DNS requests).Can you explain to me the architecture to achieve this, please?BTW, I cannot use NEDNSProxyProvider because that API requires a managed/supervised device.
Post not yet marked as solved
Hello,When using crashlytics to distribute my app to my testers, I want they have the possibility to test the binary file using Instruments to see performance or leaks (or similar). I'd like to avoid they use xcode to compile the app (so they don't have to work with git, versioning, xcode, provisioning profiles...)I tried to attach Instruments to the app distributed using crashlytics and running in a actual phone. But I receive this error in Instruments: "(After Run Ended): Error: Unable to attach to task; port invalid."Is this technically possible? Do I have to compile the app (and deploy) with any special flag?I have to say that if I use xcode to compile the app with that device and the cable, then Instruments works perfectly.Note: The reason of using Crashlytics is because of the company I am working on. Would be different if I tell them to use testflight?Thanks in advance.