Post

Replies

Boosts

Views

Activity

SimpleWatchConnectivity sample - modernizing it
Dear Experts, I have been looking at thr SimpleWatchConnectivity sample code: https://developer.apple.com/documentation/watchconnectivity/transferring-data-with-watch-connectivity There are a couple of things in there that look out of date. Firstly, it uses a WKApplicationDelegate to receive the background tasks. I believe this can probably be entirely removed, and replaced with .backgroundTask(.watchConnectivity) { ... } on the App. Is that true? What do I need something inside the { ... } there? Secondly, it is using NSNotificationCenter to send received data from the WCSessionDelegate to the SwiftUI view hierarchy. Is there a better way to do that? I have spent a while trying to work out how a WCSessionDelegate class can connect to a binding to a SwiftUI @State property, and cause the UI to update in response to received data, but I haven't made it work. Are there any newer examples of how to do this? I'm currently only trying to send some simple applicationContext state from the phone to the watch and have some views update to show the latest values. Thanks, Phil.
3
0
416
Dec ’24
Per-project ProjectName-Swift.h, rather than per-target
Dear Experts, I have an Xcode project that generates two iOS app targets. Most of the code is shared between the two targets. Let's call them "Project", "App1" and "App2". I have some Swift code that is called from objC++. To make this work, in the objC++ files currently I #include "App1-Swift.h". Clearly this only works when building App1. What's the right way to set this up to work for both targets? Looking at the build settings, currently the "Generated Header Name" is set to "$(SWIFT_MODULE_NAME)-Swift.h". Presumably, SWIFT_MODULE_NAME expands to the target name. There are various possible ways to fix this, but which one is "right"? I bet that if I fix it in the wrong way, something else will go wrong later. I could: Change the objC++ to #include different headers depending on the target being built. Change the build setting to use the project name (from a variable?) instead of the SWIFT_MODULE_NAME. Somehow cause SWIFT_MODULE_NAME to equal the project name, rather than the target name. Any advice? Thanks.
0
0
268
Nov ’24
Battery state notifications, when app is in the background
Does anyone know how battery state notification (UIDevice.batteryStateDidChangeNotification) is supposed to work regarding app foreground/background state? Assume there is no other reason why the app is running in the background. I have enabled UIDevice.current.isBatteryMonitoringEnabled when the app was in the foreground. What should happen if the external power is later connected or removed when the app is in the background? The docs don't mention this. Possibilities include I don't get a notification, so I should check the state myself when the app next comes to the foreground. I'll get a notification when the app next comes to the foreground, if the state changed while it was in the background. The app will be woken up in the background to receive the notification. The app will be kept running in the background while isBatteryMonitoringEnabled is true. It looks as if it's doing either 3 or 4, which I find a bit surprising. But is this influenced by the fact that it's connected (wirelessly) to the debugger?
4
0
410
Nov ’24
Why I am seeing "Grace Period" events for my new subscription app?
Dear All, I've recently released a new app with a subscription. It has a 3-day free trial and a 1-year subscription, and I've enabled a grace period of 16 days, but the grace period is enabled only for paid-to-paid renewals. As it's a new app, no-one has reached the end of their subscription yet; there will not have been any paid-to-paid renewals. Yet I see a small number of "enter grace period" and "renewal from grace period" events reported in App Store Connect. Can anyone explain why this could be?
3
1
614
Sep ’24
When is NSMotionUsageDescription shown?
I'm using CMMotionManager startDeviceMotionUpdatesUsingReferenceFrame: CMAttitudeReferenceFrameXTrueNorthZVertical and have set the NSMotionUsageDescription ("Privacy - Motion Usage Description") property in the info.plist. But I don't see a permissions popup. I also don't see any mention of this in the app's section of the Settings app. When is this usage description string used? I wonder if there is some connection between the motion permission and the location permission, which I also use?
5
0
1k
Aug ’24
Drag-and-drop from Safari
I am experimenting with drag-and-drop on iPadOS. If I drag a JPEG image from a webpage in Safari to my app, I get items of types public.jpeg and public.url. Typically, the URL is the URL of the image. If, however, the image is itself a link, then the URL seems to be the target of the link. Is there some way that I can always get the URL of the image itself? Is there some way that I can determine whether the URL I have received is the URL of the image or of a link?
0
0
452
Jul ’24
Should I get UIPasteboardChangedNotification when another app changes the clipboard?
Dear Experts, My app is observing UIPasteboardChangeNotification in order to enable/disable its paste button. I do not seem to be getting any notifications when other apps copy to the clipboard. For example, if I have my app and Safari in split-screen on my iPad and I copy something in Safari, I don't see the notification. Similarly if I switch to Safari, copy something, and switch back to my app, I do not get the notification either when I'm in the background or when I return to the foreground. The only time that I see UIPasteboardChangedNotification is when the clipboard is modified by my app itself. Is this supposed to work? Is there some other way to get notified when the clipboard is changed by another app? Thanks.
0
0
359
Jul ’24
PHPickerViewController in Limited Access photos mode
Dear Experts, In "limited access" photos mode, I present a PHPickerViewController. It shows the entire photo library, with a note at the top saying that the app can only access the items that I select. I select a photo. In the delegate method, I get a PHPickerResult containing a plausible-looking string for the assetIdentifier. It's the same string that I get for that photo in "full access" mode. Should this photo now be accessible, or do I need to do something else at this point? When I call fetchAssetsWithLocalIdentifiers using this assetIdentifier, I get no results. When I call cloudIdentifierMappingsForLocalIdentifiers, I get error PHPhotosErrorIdentifierNotFound. In "full access" mode, both work OK. What am I missing? Thanks.
3
0
978
Jul ’24
Acceptable location purpose strings
Does anyone have recent experience of what App Review consider acceptable for location purpose strings these days? My map apps simply display a blue spot on the map showing your current location when you turn on the app's location button. That data doesn't leave the app; I'm not selling it to anyone, or doing anything nefarious. For years, I've had concise location purpose strings such as "Your location will be shown on the map". Now, App Review seem to find that inadequate. They say: "One or more purpose strings in the app do not sufficiently explain the use of protected resources. Purpose strings must clearly and completely describe the app's use of data and, in most cases, provide an example of how the data will be used. Next steps: Update the ... location purpose string to explain how the app will use the requested information and provide an example of how the data will be used. " I've just look at what Apple Maps uses as its purpose string, and it's just "Your location is used to show your position on the map, get directions, estimate travel times, and improve search results." I'm only doing the first of those things, so surely "Your location is used to show your position on the map" would get approved, right? Wrong! I have similar issues with the photos purpose string.
4
2
1.3k
Jun ’24
Does SubscriptionStoreView .storeButton(for:.policies) work?
I've added .storeButton(.visible, for:.policies) to my SubscriptionStoreView, and the buttons do appear, but when I tap on them I get a sheet that just says "Terms of Service Unavailable / Somethng went wrong. Try Again.". (similar for Privacy Policy). Is this expected in development? Will these start working correctly in production? (and, more importantly, in App Review?) The docs say that these use the values (i.e. URLs) set in App Store Connect, but that I can override those. This is a new app. Is that wrong, do I need to set the URLs explicitly? Edited to add: the console reports: Failed to fetch terms of service and privacy policy: Error Domain=NSURLErrorDomain Code=-1011 "(null)"
4
1
818
Jun ’24
Moving the selection handles in UITextSelectionDisplayInteraction
I am attempting to use UITextSelectionDisplayInteraction. It basically works, but I'm unsure how the selection handles are supposed to work. The documentation is minimal and the WWDC video (2023 session 10058) doesn't say much either. As the name suggests, it seems that this interaction only displays the cursor, selection background, and handles. As I change the selection, it updates these views. So if I want the user to be able to drag the selection handles I need to implement that, right? OK, so I add a gesture recognizer to each selection handle. But this doesn't seem to do anything, i.e. the gesture recognizer action never seems to be invoked. Maybe I'm doing something wrong - but I'd like to understand what is supposed to happen. Is adding a pan gesture recognizer to each selection handle the right approach? P.S. I wanted to tag this "WWDC2023-10058", but the per-session tags seem to have disappeared. Is this a forum bug, or deliberate?
0
0
507
May ’24
Does UITextInteraction have a way to dismiss the edit menu?
If I use UIEditMenuInteraction to present an edit menu, it has a dismissMenu method that I can call to remove the menu when necessary. When I use UITextInteraction, I get an edit menu automatically that is normally presented and dismissed at appropriate times. But sometimes I want to dismiss the menu myself, and I can't find a way to do that. Am I missing something? I was hoping to find that UITextInteraction inherited from UIEditMenuInteraction, or had some other way to access the underlying menu in order to dismiss it. But it seems that the menu must be a private part of the UITextInteraction implementation. The particular case that I need to deal with is when I call resignFirstResponder. This seems to cause the keyboard to close and the insertion point and any selection to be hidden, but if an edit menu was shown then it remains visible (a ghost!). If anyone knows of an alternative to resignFirstResponder that will make UITextInteraction tidy up properly, that would also be useful to know. Thanks for any suggestions!
2
0
809
May ’24