Post

Replies

Boosts

Views

Activity

Help with styling PasteButton in SwiftUI
iOS 16 introduced a new clipboard privacy protection feature which requires that the user explicitly allow the app to use UIPasteboard every time they take that action. This makes custom paste buttons (designed to make it faster for the user to paste, instead of needing to use the text editing menu) very tedious to use. Apple introduced a new SwiftUI element, PasteButton, to take the place of this custom approach. The problem is that I can't seem to find any good documentation on how to style the button. Previously I had a series of small icon buttons for quick controls, but now this new UI element is throwing things off. See the images below for an example: Old: New: This also causes UI inconsistencies between old and new iOS versions for my users, since the PasteButton is only 16.0+. Does anyone have any tips for how I can get the new button to look like the old one I made myself? Or at least to scale it down and make the background a circle? Here's my current code: if #available(iOS 16.0, *) {     PasteButton(payloadType: String.self) { strings in         guard let first = strings.first else { return }         linkStr = first     }     .labelStyle(.iconOnly)     .buttonBorderShape(.roundedRectangle(radius: 100))     .padding(.top, 16) } else {     // Fallback on earlier versions     Button(action: {         if let pasteStr = UIPasteboard.general.string {             linkStr = pasteStr             hideKeyboard()         }     }) {         Image(systemName: "doc.on.clipboard")             .padding([.trailing, .top, .bottom])     }     .padding(.top, 16)     .help("Paste link from clipboard") }
0
1
1.2k
Sep ’22
Cannot create new library playlist with Apple Music API
Hello, I'm writing a function that creates a new Apple Music library playlist for the user of my app. I'm successfully asking for the user's permission to access their music, and I'm able to retrieve the user's "Music User Token". Unfortunately when it comes time to make the post request, I end up getting a 403 "Forbidden" error. Here's a snippet of my code: let url = URL(string: "https://api.music.apple.com/v1/me/library/playlists")!             debugPrint("Querying: \(url.absoluteString)")             let sessionConfig = URLSessionConfiguration.default             let authValue: String = "Bearer \(appleMusicAuthKey)"                          var userToken: String             let userTokenProvider = MusicUserTokenProvider.init()             do {                 userToken = try await userTokenProvider.userToken(for: appleMusicAuthKey, options: MusicTokenRequestOptions.init())                 debugPrint("Got user token")                 sessionConfig.httpAdditionalHeaders = ["Authorization": authValue, "Music-User-Token": userToken]                 var request = URLRequest(url: url)                 request.httpMethod = "POST"                 debugPrint(userToken)                 let urlSession = URLSession(configuration: sessionConfig)                                  do {                     let (data, response) = try await urlSession.upload(for: request, from: jsonData!)                     if let httpResponse = response as? HTTPURLResponse {                         print(httpResponse.statusCode)                                                  if (httpResponse.statusCode == 201) {                             debugPrint("Created new playlist!")                         } else {                             debugPrint("Could not create the playlist")                         }                     }                 } catch {                     debugPrint("Error loading \(url): \(String(describing: error))")                 }             } catch {                 debugPrint("Could not get user token")             } (Please excuse some of the messy code, still prototyping this) As far as I can tell, my developer token is fine, and the weirdest part is that I had it working with very similar code earlier. I cannot figure out what's wrong or what I'm missing.
2
1
984
Aug ’22