Post

Replies

Boosts

Views

Activity

NSMeasurement not converting between UnitInformationStorage Correctly
I'm trying to use (NS)Measurement to convert any higher unit into kilobytes. let mes = Measurement(value: 3, unit: UnitInformationStorage.megabytes) let kilobytes = mes.converted(to: .kilobytes).value I expect kilobytes to be 3072, but instead I get 3000. I get that in computing we often do rounding and for many people 1000 kilobytes = 1MB when in reality it should be 1024 kilobytes = 1MB. Is there any way to change this behavior?
2
0
608
Jan ’22
Entering the actor through two async let calls hangs the app at suspension point.
I have been trying to work with the image downloader code provided in the session to see if I could download two images at once and cache them in the actor. For some reason, when I enter the download method on the actor with two consecutive async let calls, the app hangs at the deepest suspension point. I am providing a very minimum code you can copy and paste into a new iOS Storyboard-based project, replacing the code in ViewController.swift: enum ImageDownloadError: Error {     case badImage } actor ImageDownloader {     private var cache: [URL: UIImage] = [:]     func image(from url: URL) async throws -> UIImage {         if let image = cache[url] {             return image         }         print("Downloading image")         let image = try await downloadImage(url: url)         print("Downloaded image")         cache[url] = image         return image     }     private func downloadImage(url: URL) async throws -> UIImage {         let imageRequest = URLRequest(url: url)         let (data, imageResponse) = try await URLSession.shared.data(for: imageRequest)         guard let image = UIImage(data: data), (imageResponse as? HTTPURLResponse)?.statusCode == 200 else {             throw ImageDownloadError.badImage         }         return image     } } class ViewController: UIViewController {     override func viewDidLoad() {         super.viewDidLoad()         async {             await downloadImages()         }     }     func downloadImages() async {         let downloader = ImageDownloader()         let imageURL = URL(string:  "https://www.andyibanez.com/fairesepages.github.io/tutorials/async-await/part3/3.png")!         async let downloadedImage = downloader.image(from: imageURL)         //async let sameDownloadedImage = downloader.image(from: imageURL) // Uncomment to see the bug         var images = [UIImage?]()         images += [try? await downloadedImage]         //images += [try? await sameDownloadedImage]         print("Finished everything")     } } If you uncomment the code marked as Uncomment to see the bug, you will see that the code will go through many different await calls, but it will hang on the ine in the URLSession.shared.data(for: imageRequest) call. The app just hangs there and doesn't continue executing. Commenting the same line will let it work fine. Are there any known workarounds for this? I would love to get this to work. I have opened a feedback on this, linking it just in case FB9213145
0
0
643
Jul ’21
Making an app that can be set the default web browser.
I have a few web browsers on my phone (Firefox, Chrome) and none of them can currently be set as default web browsers on iOS 14. I am assuming that there needs to be some work done in the app in order for the system to consider it a web browser and show in the list of browsers you can set as default. I am also assuming that the web browser needs to comply with some sort of minimum functionality in order to work as a default. I have been looking for a while for the documentation for this, and I haven't had any luck. What do I need to be able to set an app as a default web browser? A plist? Conform to a protocol? Anything else? Any points to the documentation will be appreciated as I cannot seem to find it on my own.
3
1
3.2k
Jun ’20
Unable to upload hosted content
I'm building an app that allows users to buy "themes". The themes are created as IAPs that will be used with Apple's Hosted Content feature so users download them when they purchase it. To create my IAP content, I created a new target of type "In-App Purchase Content" and created the IAPs in iTunes Connect. I'm archiving the IAP within Xcode and trying to upload it, which gives me this error: No application records were found. In-app purchase content must be ready for upload on iTunes Connect before it can be validated or submitted from within Xcode. Here's a couple of things to keep in mind: 1. I do not have any pending agreements. 2. The Product ID on iTunes Connect matches the Product ID on my In-App Purchase Content target. 3. The IAPs in question have the status "waiting for upload". 4. If it matters, my themes are simply .plist files. I verified they are getting correctly bundled in the resulting pkg.5. This app is still under development and it has never hit the App Store yet. STEPS TO REPRODUCE 1. Create a new In-App Purchase. 2. Enable Hosted Content for this IAP. 3. Give it a valid product ID using reverse DNS notation. (com.fairese.Mignori.IAP.ThemeCollection for example). 4. Fill in all the required metadata until the status of the IAP changes to "Waiting for Upload". 5. On Xcode, create a new project or target of type "In-App Purchase Content". Give it the same Product ID you created on Step 3. 6. Drag some plist files (this is because my IAPs are plist files) at the same level of the ContentInfo.plist file of the new target or project. 7. If you created a new target, make it the active target. 8. Archive the In-App Purchase Content IAP and wait for the organizer Window to show up. 9. Under the "In-App Purchases" section in organizer, select your newly created In-App Purchase Content. 10. Click "Upload to App Store...". 11. If prompted to select a development team, select the development team that has the app that owns the IAP you are trying to upload. Click next. 12. The next screen will attempt to load the Product IDs (I assume), but it will fail with the error "No application records were found."Has anyone dealt with this? I have been searching like crazy for a solution for this, but I can't manage to upload my hosted content to Apple. A bit of a bummer the functionality was removed from Application Loader in latest versions.
9
0
2.5k
Jun ’18
URLSessionUploadTask getting automatically cancelled instantly
I'm having this weird issue in which a newly created URLSessionUploadTask gets cancelled instantly. I'm not sure if it's a bug with the current beta of Xcode 8.I'm trying to build a Framework project.I suspect it might be a bug because the code I'm about to post ran fine exactly once. No changes were made to it afterwards and then it simply stopped working. Yes, it literally ran once, and then it stopped working. I will post the error near the end.I will post the code below, but first I will summarize how the logic here works.My test, or user-exposed API (IE for use in Playgrounds or directly on apps), calls the `authorize` method. This `authorize` method will in turn call `buildPOSTTask`, which will construct a valid URL and return a `URLSessionUploadTask` to be used by the `authorize` method.With that said, the code is below:The session:internal let urlSession = URLSession(configuration: .default)Function to create an upload task: internal func buildPOSTTask(onURLSession urlSession: URLSession, appendingPath path: String, withPostParameters postParams: [String : String]?, getParameters getParams: [String : String]?, httpHeaders: [String : String]?, completionHandler completion: URLSessionUploadTaskCompletionHandler) -> URLSessionUploadTask { let fullURL: URL if let gets = getParams { fullURL = buildURL(appendingPath: path, withGetParameters: gets) } else { fullURL = URL(string: path, relativeTo: baseURL)! } var request = URLRequest(url: fullURL) request.httpMethod = "POST" var postParameters: Data? = nil if let posts = postParams { do { postParameters = try JSONSerialization.data(withJSONObject: posts, options: []) } catch let error as NSError { fatalError("[\(#function) \(#line)]: Could not build POST task: \(error.localizedDescription)") } } let postTask = urlSession.uploadTask(with: request, from: postParameters, completionHandler: completion) return postTask }The authentication function, which uses a task created by the above function (I have removed a lot of irrelevant code): public func authorize(withCode code: String?, completion: AccessTokenExchangeCompletionHandler) { // I hav let obtainTokenTask = buildPOSTTask(onURLSession: self.urlSession, appendingPath: "auth/access_token", withPostParameters: nil, getParameters: body, httpHeaders: nil) { (data, response, error) in if let err = error { completion(error: err) } else { print("Response is \(response)") completion(error: nil) } } obtainTokenTask.resume() }I caught this error in a test: let testUser = Anilist(grantType: grant, name: "Test Session") let exp = expectation(withDescription: "Waiting for authorization") testUser.authorize(withCode: "a valid code") { (error) in if let er = error { XCTFail("Authentication error: \(er.localizedDescription)") } exp.fulfill() } self.waitForExpectations(withTimeout: 5) { (err) in if let error = err { XCTFail(error.localizedDescription) } }It always fails instantly with this error:Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://anilist.co/api/auth/access_token?client_secret=REMOVED&grant_type=authorization_code&redirect_uri=genericwebsitethatshouldntexist.bo&client_id=ibanez-hod6w&code=REMOVED, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://anilist.co/api/auth/access_token?client_secret=REMOVED&grant_type=authorization_code&redirect_uri=genericwebsitethatshouldntexist.bo&client_id=ibanez-hod6w&code=REMOVED}Here's a few things to keep in mind:- The URL used by the session is valid.- All credentials are valid.- It fails *instantly* with a "cancelled" error, that simply did not happen before. I am not cancelling the task anywhere, so it's being cancelled by the system. It doesn't look like it has time to hit the network, because the test fails as soon as it is started.- **It also fails on Playgrounds with indefinite execution enabled**. This is not limited to my tests.Here's a list of things I have tried:- Because I suspect this is a bug, I first tried to clean my project, delete derived data, and reset all simulators. None of them worked.- Even went as far restarting my Mac...- Under the small suspicion that the upload task was getting deallocated due to it not having any strong pointers, and in turn calling `cancel`, I also rewrote `authorize` to return the task created by `buildPOSTTask` and assigned it to a variable in my test. The task was still getting cancelled.I'm out of ideas of what to try. The generated logs don't seem to have any useful info.(If anyone is willing to go above and beyond to help me, I can upload the whole project here, since it will be open source anyway. The project is really small currently, consisting of three small Swift files and one test file).
2
0
7.1k
Jul ’16
Feedback app says I'm not enrolled.
I have quite a lot of feedback to send regarding iOS 9.3, but the feedback app says I'm not enrolled in any beta program. I downloaded the config profile from the member center directly with the very same account I'm trying to log with into the Feedback Center app and OTA'd my phone/So I'm using everything "officially" provided by Apple by the feedback center says I'm not authorized anyway.What should I do? Should I open standard radars like always? The Feedback app makes it much nicer and easier to send feedback I'd prefer to use it, but if it thinks I'm not authorized...
6
0
1.5k
Jan ’16