Welcome to the Apple Developer Forums

Post your questions, exchange knowledge, and connect with fellow developers and Apple engineers on a variety of software development topics.

For questions about using Apple hardware and services, visit Apple Support Communities

Posts

Sort by:
Post not yet marked as solved
0 Replies
6 Views
(This is the duplicate of https://developer.apple.com/forums/thread/718948 because I accidentally marked it as completed.) I am trying to test Ask to Buy for consumable product. When the transaction was approved, the process stops at a breakpoint in Transaction.updates. However, when I call Transaction.currentEntitlements after that, I cannot handle transaction of consumables. Here is my code. func newTransactionListenerTask() -> Task<Void, Never> { Task(priority: .background) { for await verificationResult in Transaction.updates { guard case .verified(let transaction) = verificationResult,             transaction.revocationDate == nil         else { return }         // Breakpoint stops here await refreshPurchasedProducts()         await transaction.finish()         }    } } func refreshPurchasedProducts() async { for await verificationResult in Transaction.currentEntitlements { guard case .verified(let transaction) = verificationResult else { return } switch transaction.productType { case .consumable: // This code is not called             updateConsumablePurchaseCount(productID: transaction.productID)         default:             break }     } } I do not call transaction.finish() if the purchase result is .pending as shown in the code below.     func purchase(_ info: ConsumableProductInfo) async throws {         let result: Product.PurchaseResult         switch info {         case .coffee:             guard let coffeeProduct else { return }             result = try await coffeeProduct.purchase()         }         switch result {         case let .success(verificationResult):             switch verificationResult {             case let .verified(transaction):                 await refreshPurchasedProducts()                 await transaction.finish()             case let .unverified(_, verificationError):                 throw verificationError             }         case .pending, .userCancelled:             break         @unknown default:             break         }     } When I test Ask to Buy I'm not calling transaction.finish() so I should be able to get the consumable transaction in Transaction.currentEntitlements, however I couldn't. I found a blog post that is similar to this problem: https://iosexample.com/implementing-and-testing-in-app-purchases-with-storekit2-in-xcode-13-swift-5-5-and-ios-15/ It says that "In tests I've done transactions for consumables do not remain in the receipt, even if you omit to call finish()." So I wonder if this is a bug or problem in my coding.
Posted
by
Post not yet marked as solved
0 Replies
15 Views
I'm trying to train an image classification model in CreateML application using the DF20 dataset from https://sites.google.com/view/danish-fungi-dataset?pli=1 When I tap on Train, the application begins to extract the necessary data. This process ends after the first cca 30 000 images. The footer shows Unexpected error and (strangely) a new window opens to Create New Project. No further info about the error is provided anywhere. The training succeeds when using a smaller portion of the dataset (<20 000 images). Anything over 40 000 images results in this error. Any ideas?
Posted
by
Post not yet marked as solved
0 Replies
17 Views
I have a simple record called UserCode, the name of the record is created by each user entering the app for first time creating an alphanumeric random string of 8 letters. When I try to query, or fetch this record FROM THE APP it simply gives me error 11 (not exists) or records.length==0 if i try to query. If i do it from the dashboard all fine, i can query and fetch. The name of the record is set as searchable, also tried with queryable. Nothing works. The icloud account I use in the app is the same one as the dasboard. All permissions are open for that record, except world write. Any explantion or sollution? i've been 2 days around this and i cant find a way.
Posted
by
Post not yet marked as solved
3 Replies
33 Views
below is my code of reading data from HealthKit for Multiple Data but for reading Multiple data using Set() it shows "Cannot convert value of type 'Set' to expected argument type 'HKQuantityType' " func readData(completion: @escaping (HKStatisticsCollection?)-> Void){         let stepCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!         let MoveCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.appleMoveTime)!         let DistanceCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!         let Activitysummary = Set([stepCount,MoveCount,DistanceCount])                  let startDate = Calendar.current.date(byAdding: .day, value: -7, to: Date())         //MARK: here we setting our start time at 12.00 AM         let anchorDate = Date.monday12AM()         //MARK: we going to calculate the value for each day         let daily = DateComponents(day : 1)         let predicate = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: .strictStartDate)         //MARK: .cummulativesum -> iPhone and Apple Watch Difference         query =  HKStatisticsCollectionQuery(quantityType: Activitysummary, quantitySamplePredicate: predicate,options: .cumulativeSum, anchorDate: anchorDate, intervalComponents: daily) //MARK: here in ActivitySummary it show the error                  query!.initialResultsHandler = { query,statisticsCollection, error in             completion(statisticsCollection)         }         if let healthStore = healthStore, let query = self.query{             healthStore.execute(query)         }     }
Posted
by
Post not yet marked as solved
2 Replies
43 Views
According to the document: "the URL Loading System handles various aspects of the HTTP protocol for you (HTTP 1.1 persistent connections, proxies, authentication, and so on). As part of this support, the URL Loading System takes responsibility for certain HTTP headers: Content-Length Authorization Connection Host Proxy-Authenticate Proxy-Authorization WWW-Authenticate If you set a value for one of these reserved headers, the system may ignore the value you set, or overwrite it with its own value, or simply not send it. Moreover, the exact behavior may change over time. To avoid confusing problems like this, do not set these headers directly." Looks like we'd better avoid setting "proxy-authorization" directly: [req setValue:authenticationValue forHTTPHeaderField:@"Proxy-Authorization"]; or [config setHTTPAdditionalHeaders:@{@"Proxy-Authorization": authHeader  } ];, instead, should go to the session delegate. However, we would have 2 "requests" if we follow the authentication challenge if we have credentials already: https://developer.apple.com/documentation/foundation/url_loading_system/handling_an_authentication_challenge?language=objc. So is there any API or other safe way to set "Proxy-Authorization" for nsurlsessionconfig at the "beginning" if we got the credential already? Thanks in advance.
Posted
by
Post not yet marked as solved
0 Replies
30 Views
Hi, guys I am making a project that plays video using Swift AVPlayer. There is a problem that the video stops, or there is only sound but no video. When a video URL is received and played through AVPlyer, the file extension is HLS (.m3u8) Same issue with both AVPlayer and Safari. However, it plays normally in Chrome. Is it a video file problem? Or is there something the app needs to handle? This is the sample video URL I am using https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8 https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8 http://d3rlna7iyyu8wu.cloudfront.net/skip_armstrong/skip_armstrong_stereo_subs.m3u8 self.playerItem = AVPlayerItem(url: URL(string: urlString)!) self.playerItem?.addObserver(self, forKeyPath: #keyPath(AVPlayerItem.status), options: [.initial, .new], context: &self.playerItemContext) self.playerItemObserver = true if self.player == nil { self.player = AVPlayer(playerItem: self.playerItem) self.playerLayer = AVPlayerLayer(player: self.player) self.player?.play() return } I am using the above code to insert the url and play it.
Posted
by
Post not yet marked as solved
0 Replies
24 Views
UISearchBar crashes, but I don't know what's going on. From the code, there is no problem here.Attached is my crash log. crash.log search_bar.barTintColor = .init(hex: 0xececec) search_bar.tintColor = LightText1() search_bar.placeholder = "Search Matches" search_bar.searchBarStyle = .minimal search_bar.backgroundImage = UIImage() search_bar.delegate = self if #available(iOS 13.0, *) { search_bar.searchTextField.font = Secondary_Body1_Medium() search_bar.searchTextField.backgroundColor = .clear search_bar.searchTextField.textColor = LightText1() search_bar.searchTextField.borderStyle = .none search_bar.searchTextField.layer.cornerRadius = 4 search_bar.searchTextField.layer.masksToBounds = true search_bar.searchTextField.backgroundColor = UIColor(hex: "#F7F7F7") }
Posted
by
Post not yet marked as solved
0 Replies
25 Views
Safari iOS 16 started to support the new AVIF image format according to this blog post https://webkit.org/blog/13152/webkit-features-in-safari-16-0/ I tested it with the url https://avif-support-test.glitch.me/ It works well on my iPhone, macOS Ventura but not iOS Simulator 16.2. It tried to fetch the image resource but got an error "An error occurred trying to load the resource"
Posted
by
Post not yet marked as solved
1 Replies
28 Views
I have prepared an example to easier describe what I am want to ask: @interface ViewController () @end @implementation ViewController {   UIColor *_color; } - (void)viewDidLoad {   [super viewDidLoad];       [self getStaticVC];       __block CFTypeRef test1;   __block CFTypeRef test2;   __block CFTypeRef test3;   @autoreleasepool {     test1 = [self getVC];     test2 = [self getVC];     test3 = [self getVC];           NSLog(@"Test1: %lld", CFGetRetainCount(test1));     NSLog(@"Test2: %lld", CFGetRetainCount(test2));     NSLog(@"Test3: %lld", CFGetRetainCount(test3));   } } - (UIViewController *)getStaticVC {   static UIViewController *vc;   if (!vc) {     vc = [UIViewController new];   }   return vc; } - (CFTypeRef)getVC {   return (__bridge CFTypeRef)[self getStaticVC]; } @end For this code above, if I will run it, it will print always that retain count is 4, but if I will change implementation of the method getVC to this: - (CFTypeRef)getVC { UIViewController *temp = [self getStaticVC];   return (__bridge CFTypeRef)temp; } Code will always print retain count as 1. My guess it is related to reference storage qualifier that is assigned to returned values from this methods. For value returned from getVC there are no storage qualifier, cos it is a void *, so I guess when we assigning to UIViewController *temp it likely mean that we are getting __strong local variable that is deallocated right after getVC finish, but for my first example, it seems like getVC return an __autoreleasing reference, otherwise I have no idea why reference count is growing ?
Posted
by
Post not yet marked as solved
0 Replies
27 Views
I've just received the financial report for december 2022 and it shows i've only sold 1 unit when in reality I've sold 358. Also, the 1 unit that is shown somehow has an adjustment that brings the payout to $0 Has this ever happened to anybody else? Any advice? Thanks in advance. Matteo
Posted
by
Post not yet marked as solved
0 Replies
24 Views
I'm configuring a serial connection to use CTS/RTS hardware flow control. My code seems to apparently turn on this setting when looking at the behavior on the serial line: after deasserting CTS (going high), the transmission is paused and gets resumed when reasserting CTS (going low). So far, so good. But while CRTSCTS is present in c_cflag before setting the configuration with tcsetattr - it is no longer present when reading the configuration back afterwards with tcgetattr. See my test program below. Any ideas what I'm missing here? #include <errno.h> #include <fcntl.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h> #include <unistd.h> char const * const PATTERN = " 0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; void print_termios(const struct termios *config) { printf(" c_iflag: 0x%08lx\n", config->c_iflag); printf(" c_oflag: 0x%08lx\n", config->c_oflag); printf(" c_cflag: 0x%08lx\n", config->c_cflag); printf(" c_lflag: 0x%08lx\n", config->c_lflag); printf(" c_cc:"); for (size_t i = 0; i < NCCS; ++i) { printf(" 0x%02x", config->c_cc[i]); } printf("\n"); printf(" c_ispeed: %lu\n", config->c_ispeed); printf(" c_ospeed: %lu\n", config->c_ospeed); } int main(int argc, char **argv) { int result = -1; printf("hello serial afficionados!\n"); if (argc < 2) { fprintf(stderr, "device name missing\n"); exit(1); } printf("device: %s\n", argv[1]); printf("about to open ...\n"); const int fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { fprintf(stderr, "opening %s failed: %s (%d)\n", argv[1], strerror(errno), errno); exit(1); } struct termios config = { 0 }; printf("tcgetattr ...\n"); result = tcgetattr(fd, &config); if (result < 0) { fprintf(stderr, "tcgetattr failed: %s (%d)\n", strerror(errno), errno); exit(1); } print_termios(&config); printf("cfmakeraw ...\n"); cfmakeraw(&config); print_termios(&config); printf("configuring flags ...\n"); config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | INPCK | IGNPAR | IGNCR | ICRNL | IXON | IXOFF); config.c_oflag &= ~OPOST; config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); config.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB | CRTSCTS); config.c_cflag |= (CS8 | PARENB | CREAD); config.c_cflag |= CRTSCTS; config.c_cflag |= CLOCAL; print_termios(&config); printf("cfsetispeed ...\n"); result = cfsetispeed(&config, 115200); if (result < 0) { fprintf(stderr, "cfsetispeed failed: %s (%d)\n", strerror(errno), errno); exit(1); } printf("cfsetospeed ...\n"); result = cfsetospeed(&config, 115200); if (result < 0) { fprintf(stderr, "cfsetospeed failed: %s (%d)\n", strerror(errno), errno); exit(1); } print_termios(&config); printf("tcsetattr ...\n"); result = tcsetattr(fd, TCSANOW, &config); if (result < 0) { fprintf(stderr, "tcsetattr failed: %s (%d)\n", strerror(errno), errno); exit(1); } print_termios(&config); printf("tcgetattr for checking status ...\n"); result = tcgetattr(fd, &config); if (result < 0) { fprintf(stderr, "tcgetattr failed: %s (%d)\n", strerror(errno), errno); exit(1); } print_termios(&config); printf("about to transmit ...\n"); const size_t length = strlen(PATTERN); size_t count = 0; while (true) { size_t written = 0; while (written < length) { const ssize_t write_result = write(fd, PATTERN, length - written); if (write_result < 0) { fprintf(stderr, "failed write: %ld (%s (%d))\n", write_result, strerror(errno), errno); exit(1); } else { written += write_result; } } result = tcdrain(fd); if (result != 0) { fprintf(stderr, "failed to tcdrain: %s (%d)\n", strerror(errno), errno); exit(1); } count += 1; if (count % 100 == 0) { printf("chunk %ld\n", count / 100); } } }
Posted
by
Post not yet marked as solved
0 Replies
44 Views
I started dis app attempt last year and decide to retake on it. But since I updated to the last version of Xcode I started to hace this issue that I can't seem to figure it out. I was comparing it with another version of this same project that I had and I still don't understand the error. English ain't my first language, sorry for any misunderstanding.
Posted
by
Post not yet marked as solved
0 Replies
28 Views
Hello everyone! I am using the web version of the Apple Music Kit API, and similar to how Apple is able to produce a user's year in rewind playlist showing the most played artists/songs from a year, I am trying to replicate it for either a year or all time. I have been searching the internet for days trying to figure it out, but I've been completely stuck. I am able to make the following HTTP request successfully. GET https://api.music.apple.com/v1/me/library/songs/ which returns back the user's library of songs, but I haven't figured out how to get the play count. I have tried adding a query like such ?extend=playCount, but that doesn't work. I can see here that the Swift Music Kit API is able to extend a play count property, but I haven't been able to figure it out for Web. Ideally, I am looking for an endpoint that just shows a user's top artist/tracks similar to Spotify, however, whenever I try to use the heavy in rotation endpoint here, it always returns an empty array. The way that I have described is the long-roundabout way where I'll have to fetch each individual song and sort by playCount. But if anyone happens to know how I can do either of the options I've described, it will be truly appreciated ! I've seen other forums posts from years ago, but hopefully there's been a discovered way. Thank you!
Posted
by
Post not yet marked as solved
0 Replies
24 Views
I want to develop an app that collects a User's total iOS Screen Time using the Screen Time API. I know that this is possible in the most recent Screen Time API update (via the Device Activity Framework), but am unsure how to actually ask a Device for permission and then, once that permission is given, collect a User's total screen time. I've looked at the Documentation which provides sample code but do not have the proper background knowledge to understand it. How do I implement this code?
Posted
by
Post not yet marked as solved
0 Replies
29 Views
Hello all, we have been showing our users Vimeo videos in our eLearning app until recently. Everything worked fine for years. Now we have changed providers and it seems that apple is blocking the videos as they are loaded from an external server. Does anyone have an idea how we can work around this problem?
Posted
by
Post not yet marked as solved
1 Replies
45 Views
`   func submitBackgroundTasks() {    // Declared at the "Permitted background task scheduler identifiers" in info.plist    let backgroundAppRefreshTaskSchedulerIdentifier = "com.FeedX.backgroundAlerts"    let timeDelay = 10.0    do {     let backgroundAppRefreshTaskRequest = BGAppRefreshTaskRequest(identifier: backgroundAppRefreshTaskSchedulerIdentifier)     backgroundAppRefreshTaskRequest.earliestBeginDate = Date(timeIntervalSinceNow: timeDelay)     try BGTaskScheduler.shared.submit(backgroundAppRefreshTaskRequest)     print("Submitted task request")    } catch {     print("Failed to submit BGTask")    }   } I am able to submit the task and hit the breakpoint but in the LLDB i try to simulate the task using the command e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.FeedX.backgroundAlerts"] But i get the following error : error: Error [IRForTarget]: Rewriting an Objective-C constant string requires CFStringCreateWithBytes Any idea on how to solve this or run the task using a different way? Thanks.
Posted
by
Post not yet marked as solved
1 Replies
59 Views
Hello! I am trying to make my own birthdate picker implementation where I want three wheels side-by-side in an HStack. Of course, the values inside these wheels depend on each other, for example, depending on the year, February different number of days, and depending on the month, there are different number of days. I tried making a model for this, but it's returning me the "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" error in the init() line. Could you please tell me what's wrong with this? The picker view: Section {               HStack {                 Picker("Year", selection: birthdateModel.$selectedYear) {                   ForEach(birthdateModel.years, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)                 Picker("Month", selection: birthdateModel.$selectedMonth) {                   ForEach(birthdateModel.months, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)                 Picker("Day", selection: birthdateModel.$selectedDay) {                   ForEach(birthdateModel.days, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)               }             } Birthdate model: class BirthdateModel: Equatable, Hashable {       let monthWith30Days = ["Apr", "Jun", "Sep", "Nov"]   let monthWith31Days = ["Jan", "Mar", "May", "Jul", "Aug", "Oct", "Dec"]   var daysInFeb = 28   let years = 1900...Calendar.current.component(.year, from: Date())   let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]   var days = 1...31   var date = 0       let currentDate = Date()   let dateFormatter = DateFormatter()   let monthString = ""       @State var selectedYear: Int = 1900 {     didSet(year) {       if ((year % 4 == 0) && (year / 4 != 0)) {         daysInFeb = 29       }       self.changeDate()     }   }   @State var selectedMonth: String = "Jan" {     didSet(month) {       if monthWith31Days.contains(month) {         days = 1...31       }       else if monthWith30Days.contains(month) {         days = 1...30       }       else {         days = 1...daysInFeb       }       self.changeDate()     }   }   @State var selectedDay: Int = 1 {     didSet(day) {       self.changeDate()     }   }       init() {     self.dateFormatter.dateFormat = "Lll";     self.monthString = self.dateFormatter.string(from: self.currentDate);           self.selectedYear = Calendar.current.component(.year, from: Date())     self.selectedMonth = self.monthString     self.selectedDay = Calendar.current.component(.day, from: Date())     changeDate()   }       func hash(into hasher: inout Hasher) {     hasher.combine(date)   }       static func ==(lhs: BirthdateModel, rhs: BirthdateModel) -> Bool {     return lhs.date == rhs.date   }       func changeDate() {     self.date = (self.selectedYear * 10000) + ((self.months.firstIndex(where: {$0 == self.selectedMonth}) + 1) * 100) + self.selectedDay   }     }
Posted
by
Post not yet marked as solved
0 Replies
51 Views
Hey. Ive been publishing apps to the appstore for some time, but never apps with widgets. I tried to submit as usual, but the widget is not visible. So the question is: How do one publish an app to the appstore with multiple targets? In this case, an app with a widget (app and widget is individual targets within xcode)
Posted
by
Post not yet marked as solved
1 Replies
38 Views
I use WKWebView to display a web page in my app that has custom fonts with hard coded font sizes. Based on the dynamic type text size specified in the settings app by the user, I want to set a certain zoom level on the web page like this (using WKNavigationDelegate): - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='120%'" completionHandler:nil]; } This works just fine on iPhone, but on iPad the zoom level stays at 100%. Any ideas?
Posted
by
Post not yet marked as solved
0 Replies
43 Views
As documented in this article (by Apple), it is apparent that calls to the DeviceCheck App Attest API (DCAppAttestService.attestKey(_:clientDataHash:completionHandler:)) might be subject of throttling from Apple's side. Apple servers might throttle attestation traffic from a particular app to avoid becoming overwhelmed if too many instances of your app make this call simultaneously. That could happen if you have a lot of users that simultaneously receive an app update enabling App Attest. Me and my team are planning to launch a new feature in our app that utilise Apple’s DeviceCheck framework to attest cryptographic keys for our users. And as part of our internal development process and risk analysis routine, we would love to get more details about this throttling. Do anyone have any numbers on when Apple might start to throttle our API calls? Is there a limit on requests per hour or something? And is it possible to get an exception from this throttling?
Posted
by

Pinned Posts

Categories

See all