Prior to 18.x, this has worked for years. However, if a port is included, the behavior in 18.x is to return "///some/path". In all previous versions it correctly returns "/some/path".
Is this a bug, or documented change we missed?
func relativeURLString(for urlString: String) -> String? {
guard var components = URLComponents(string: urlString) else { return nil }
components.host = nil
components.scheme = nil
// WE FOUND IF YOU NIL THE PORT BEFORE HOST AND SCHEME, IT WORKS
components.port = nil
return components.string
}
General
RSS for tagDelve into the world of built-in app and system services available to developers. Discuss leveraging these services to enhance your app's functionality and user experience.
Post
Replies
Boosts
Views
Activity
I am creating an iOS app that needs to parse the text from a PDF document. I can read the entire PDF document's text using the string property, but if it's a large PDF document, this could cause delays for users.
From the documentation, I came across the beginFindString function, which seems to asynchronously, with no return?
https://developer.apple.com/documentation/pdfkit/pdfdocument/beginfindstring(_:withoptions:))
Unfortunately I cannot find examples on how to use this function or its intended purpose/functionality, so any guidance would be appreciated.
My goal is to read the PDF document one line at a time, searching for newlines ('\n'), then parsing that line as needed. I'm hoping the beginFindString function will be useful.
I've been exploring the Trails Sample App from this session at WWDC24.
The app has a TrailEntity of type AppEntity which is leveraged in multiple places throughout the app, including:
The GetTrailInfo App Intent with a trail parameter of type TrailEntity.
A parameterized App Shortcut which calls the GetTrailInfo intent.
The TrailDataManager's init calls updateSpotlightIndex(), which creates a CSSearchableItem for each Trail in the app, along with an associateAppEntity call linking the corresponding TrailEntity to each item that gets added to the CSSearchableIndex.
If you build the app and search "trails" in Spotlight, the Trails Sample App section includes instances of TrailEntity as search results. But if you comment out the App Shortcut that takes a TrailEntity as a parameter and rebuild, there are no instances of TrailEntity in the search results. In both cases, the console prints [Spotlight] Trails indexed by Spotlight.
Is this expected behavior? Why are the TrailEntity instances only appearing in Spotlight via the App Shortcut? Shouldn't the CSSearchableItem instances show up in Spotlight on their own regardless? If not, then what is the purpose of adopting Core Spotlight with App Entities? Does this add the app entities to the semantic index for "new Siri", even though they're not user facing in the Spotlight UI?
I'm getting ILMessageFilterError.networkURLUnauthorized returned in a message filter extension when calling deferQueryRequestToServer().
Googling for people who have had the same error, they didn't include the associated domain in the containing app. However I have added that.
The server is set up at https://something.com:443, it has an apple association file located at https://something.com:443/.well-known/apple-app-site-association
I have added associated domains to the app and the app extension of:
messagefilter:something.com?mode=developer
webcredentials:something.com?mode=developer
Side question 1: are both needed or just the messagefilter?
Side question 2: should the domain include the port :443?
The server isn't publicly hosted hence I've appended ?mode=developer on the end as per the documentation.
The extension's info.plist has ILMessageFilterExtensionNetworkURL added as something.com
Question 3: Does this need the port adding too?
With everything set up according to the documentation, apart from the questions above, what might be the cause of getting networkURLUnauthorized returned?
When we request auth from the AuthorizationCenter, it seems that we're only really able to allow users to control the apps on the parent's phone. Is there a way to allow us to let parents manage apps on the kid's device directly through our parent app?
For context, we have 2 different apps, one for the parent and one for the child. The child is able to purchase screen time and the parent can redeem them (activate those minutes) from their end.
There is a crash while running the project in Xcode 16.2. The project has been using CMPedometer and CoreMotion since 2020. I wonder: I did not have the NSMotionUsageDescription key added, why is it mandatory to add this key now?
“This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMotionUsageDescription key with a string value explaining to the user how the app uses this data.”
In my Catalyst app I use
func setupMailComposer() {
// Check if the device can send email
guard MFMailComposeViewController.canSendMail() else {
print("Mail services are not available")
showMailErrorAlert()
return
}
// Create and configure the mail composer
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.mailComposeDelegate = self
// Set the email details
mailComposeVC.setToRecipients(["example@example.com"])
mailComposeVC.setSubject("Subject for your email")
mailComposeVC.setMessageBody("This is the body of the email.", isHTML: false)
// Attach a file (optional)
if let filePath = Bundle.main.path(forResource: "example", ofType: "pdf"),
let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)) {
mailComposeVC.addAttachmentData(fileData, mimeType: "application/pdf", fileName: "example.pdf")
}
// Present the mail composer
self.present(mailComposeVC, animated: true, completion: nil)
}
Since I have updated to macOS 15.1 the canSendMail() function returns false although I have configured Apple Mail (like before in 15.0 where it worked flawlessly).
Hi, I have a work task that I need to do that I struggle with...
We would like to sent an email to our clients where in that email there will be a link that will redirect to App Store to our app to be downloaded.
After the app is downloaded when the user opens the app he will automatically have a promocode pasted in our registration flow promocode text field.
Has anyone had similar task ? Is it even possible ? I did some research on this but I didn't find anyone in situation that I have now...
I now that deeplinks are widely used to parse data like this, but I'm not sure if this works even when the app is not downloaded yet. Maybe that the solution will be having a two links, but that would not be very user friendly...
Do you have any advice how to do something like this or some alternatives please ?
Thank you soo much for you time and respond.
My app is available in TestFlight but has been rejected in App Review with the review feedback that the app clip "just shows a blank screen".
However, in the TestFlight app, the App Clip works as expected and brings up the clip. It also works correctly from Xcode testing.
Any ideas on what the problem could be? It is using the default App Clip link (appclip.apple.com)
iOS Message Filter Extension - deferQueryRequestToNetwork(completion:) error
I made a test app using the iOS App template and added a target using the Message Filter Extension template which invokes deferQueryRequestToNetwork(completion:) when receiving an SMS.
The app and the extension have same "Associated Domains Capabilities" with "messagefilter" pointing to a server which receives query requests and returns proper responses. The extension has the "ILMessageFilterExtensionNetworkURL" key in Info.plist file which specifies the server URL.
deferQueryRequestToNetwork(completion:) throws a com.apple.calls.messagefilter error which reads "Extension's containing app (appID ) unauthorized to defer requests to host "
I'm using the AppIntents framework introduced in iOS 16. My goal is to create an AppIntent that performs a long-running task but does open my app when run. When I run the Intent from the Shortcuts app, I see an error message that says the shortcut "was interrupted because it didn't finish executing in time." Is there a way to signal progress to the user of a long-running AppIntent or get more time from the system prior to the AppIntent being cancelled?
Hi everyone,
I have a simple question regarding App Intents. I have an intent that defines a few parameters, one of which is a Date. When the user is prompted for input, I’d like the date picker to start at a specific value (e.g., tomorrow) instead of the default current date.
Is there a way to set an initial/default value for the date parameter in an App Intent?
Thanks in advance for any guidance!
The documentation for adding a Message Filter Extension states that the Associated Domains capability should be added to the Xcode project.
But what does that mean, should it be added to the app extension, to the app, or to both the app extension and the app?
The documentation doesn't say which exactly.
The documentation (https://developer.apple.com/documentation/BundleResources/Entitlements/com.apple.developer.associated-domains)
for a message filter extension says:
If you use a private web server, which is unreachable from the public internet, while developing your app, enable the alternate mode feature to bypass the CDN and connect directly to your server.
<service>:<fully qualified domain>?mode=<alternate mode>
Where alternate mode is one of the following:
developer
Specifies that only devices in developer mode can access the domain. In this mode, you can use any valid SSL certificate on your web server, including a certificate that the system doesn’t trust.
What does it mean "you can use any valid SSL certificate on your web server"?
Does the app have to do anything with regards to this?
I have a depended watch app bundled with my iOS app.
// ...
<key>WKRunsIndependentlyOfCompanionApp</key>
<false/>
// ...
My code:
guard WCSession.isSupported() else {
return
}
let session = WCSession.default
session.delegate = self
session.activate()
public func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
// ...
if (session.activationState == .activated) {
let log = Log(isPaired: session.isPaired, isWatchAppInstalled: session.isWatchAppInstalled)
uploadLogToServer(log)
}
// ...
}
and also:
guard WCSession.isSupported() else {
return
}
let session = WCSession.default
guard session.activationState == .activated, session.isWatchAppInstalled else {
return
}
do {
try session.updateApplicationContext(...)
} catch {
uploadErrorToServer(error)
}
What I've observed is that when I query the logs in the server's database, I get entities with isPaired = false and isWatchAppInstalled = true.
Also, when I query the errors I see deviceNotPaired errors.
So my question is, does Should WCSession.isPaired property be true before accessing WCSession.isWatchAppInstalled property ?
I'm just trying to display an image that is stored in the local filesystem, but the more I dig into this the more confused I get.
So previously I used this code (it's simplified):
func findImage(name: String) -> UIImage? {
do {
let url = try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
.appendingPathComponent("MyFolder")
.appendingPathComponent("\(name).png")
guard let image = UIImage(contentsOfFile: url.path) else {
return nil
}
return image
} catch {
print(error.localizedDescription)
}
return nil
}
Notice I create the URL with just .appendingPathComponent() and turning URL to path via url.path.
It works! So what's the question?
In Improving performance and stability when accessing the file system I've read that you better use the new appendingPathComponent(_:isDirectory:), that's good, will do.
Also url.path is deprecated in iOS18. Should I use url.path(percentEncoded:) instead? What should be the value of percentEncoded when accessing the local filesystem?
In this adjacent thread I've read:
Don't use UIImage(contentsOfFile:) either, because it's a path-based API. There's no URL-based equivalent, which is an Apple clue that should be doing something else.
Is this true? Then how should I store and load my images?
Just FYI, I create images like this:
private func generateThumbnail(name: String) {
guard let drawingWidth = canvasGeo?.size.width,
let drawingHeight = canvasGeo?.size.height else { return }
let thumbnailRect = CGRect(x: 0, y: 0, width: drawingWidth, height: drawingHeight)
Task {
UITraitCollection(userInterfaceStyle: .light).performAsCurrent {
let image = self.canvasView.drawing.image(from: thumbnailRect, scale: UIScreen.main.scale)
guard let data = image.pngData() else { return } // -- HERE
do {
try FileManager.default.createDirectory(at: try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent("MyFolder"),
withIntermediateDirectories: true,
attributes: nil)
let filename = "\(name).png"
let url = try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent("MyFolder")
.appendingPathComponent(filename)
try data.write(to: url, options: .atomic) // -- and HERE
} catch {
print(error.localizedDescription)
}
}
}
}
My usecase — just save the user's PencilKit Canvas as an image and display it back to him on a different View. I'm on SwiftUI and iOS 16+.
Would be happy to learn the correct way, thanks!
I wanted to add the above capability to my up was checking in Background mode, but no availability. How can I add it.
Hi all, I'm working on a really basic counter app as a way to explore SwiftData and have come across some behavior that I don't understand. I have a very simple App Intent that increments a user-specified counter in my app. The intent doesn't throw any errors and correctly updates the CoreData store but, when I switch back to my app from the Shortcuts app (where I'm testing the app intent), the view hasn't updated. Closing and re-opening the app shows the incremented counter value but I'd like to know if it's possible to have my app's UI update when the CoreData store is updated from outside the app without relaunching the whole app.
For some brief context, here's my view and the App Intent:
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var counters: [Counter]
// ...
var body: some View {
NavigationStack {
List {
ForEach(counters) { counter in
CounterRowItem(counter: counter)
}
.onDelete(perform: deleteItems)
}
// ...
}
}
struct IncrementCounterIntent: AppIntent {
static var title: LocalizedStringResource = "Increment Counter"
@Parameter(title: "Name", optionsProvider: CounterOptionsProvider()) var name: String
func perform() async throws -> some IntentResult & ReturnsValue<Int> {
let provider = try CounterProvider()
guard let counter = try provider.fetchCounters().first(where: { $0.name == name }) else {
print("Couldn't find counter with name '\(name)'")
return .result(value: 0)
}
counter.count += 1
try provider.context.save()
return .result(value: counter.count)
}
private final class CounterOptionsProvider: DynamicOptionsProvider {
func results() async throws -> [String] {
try CounterProvider().fetchCounters().map { $0.name }
}
}
}
The functionality of authorizationStatus and requestAuthorization is completely broken. I'm using Xcode 15.3 and iOS 17.4.
Does anyone have a solution?
authorizationStatus doesn't behave as promised
Revoking authorization in the system-wide settings does not change the authorizationStatus while the app is not closed. Calls to center.authorizationStatus will still return .approved instead of .denied.
Even closing and relaunching the app after revoking authorization does not work: authorizationStatus is then .notDetermined when it should be .denied.
Tapping "Don't Allow" in the alert shown after an initial call to requestAuthorization leaves the authorizationStatus unchanged, i.e. at .notDetermined. This is contrary to the promised outcome .denied (defined as: "The user, parent, or guardian denied the request for authorization") and contrary to the definition of .notDetermined (defined as: "The app hasn’t requested authorization", when it just did).
Same issue when first tapping "Continue" followed by "Don't Allow" on the next screen.
As a consequence of authorizationStatus being broken, its publisher $authorizationStatus is worthless too.
requestAuthorization doesn't behave as promised
This is most likely a consequence of the corrupted authorizationStatus: when revoking authorization in the system-wide settings, a call to requestAuthorization opens the authorization dialogue instead of doing nothing. It is thus possible to repeatedly ask a user to authorize Family Controls.
Code sample
To reproduce, create a new SwiftUI app, add the "Family Controls" capability and a button executing the following task when tapped:
let center = AuthorizationCenter.shared
var status = center.authorizationStatus
print(status)
do {
try await center.requestAuthorization(for: .individual)
print("approved")
} catch {
print("denied")
}
status = center.authorizationStatus
print(status)
In my project, I need to decrypt the encrypted xlsx file and then parse it into xml. Is there any recommended method in iOS