Posts

Post not yet marked as solved
0 Replies
265 Views
Hello, I am new to app development. I am trying to make an iMessage app. I created it and then added a SwiftUI view. It builds just fine and the view is visible on the storyboard, but the app is not present in iMessage on Simulator or on an actual device. What's wrong? Thanks for any help. import UIKit import Messages import SwiftUI class MessagesViewController: MSMessagesAppViewController { var hostingController: UIHostingController<CalendarView>? override func viewDidLoad() { super.viewDidLoad() } override func willBecomeActive(with conversation: MSConversation) { super.willBecomeActive(with: conversation) let swiftUIView = CalendarView() let hostingController = UIHostingController(rootView: swiftUIView) addChild(hostingController) view.addSubview(hostingController.view) hostingController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)]) hostingController.didMove(toParent: self) self.hostingController = hostingController } override func didResignActive(with conversation: MSConversation) {} override func didReceive(_ message: MSMessage, conversation: MSConversation) {} override func didStartSending(_ message: MSMessage, conversation: MSConversation) {} override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {} override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {} override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {} }
Posted Last updated
.
Post not yet marked as solved
1 Replies
458 Views
Hello, I’ve been trying to play system sounds in my app, but this hasn’t really been working. I am frequently switching between speech recognition (Speech framework) and sounds, so perhaps that’s where the issue lies. However, despite my best efforts, I haven't been able to solve the issue. I've been resetting the AVAudioSession category before playing a sound or starting speech recognition (as depicted in the code snippet below), to no avail. Has this happened to anyone else? Does anybody know how to fix the issue? recognizer = nil try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) try? AVAudioSession.sharedInstance().setActive(true) AudioServicesPlaySystemSound(1113) try? AVAudioSession.sharedInstance().setCategory(.record, mode: .spokenAudio, options: []) try? AVAudioSession.sharedInstance().setActive(true) recognizer = SpeechRecognition(word: wordSheet) recognizer!.startRecognition() Thank you.
Posted Last updated
.
Post not yet marked as solved
1 Replies
420 Views
Hello, The appearance of one of my buttons is not updating after being tapped. I have had no trouble doing the exact same thing in my other views, but here it simply doesn't work. The "heart" button will keep its original appearance (in this case an unfilled heart) no matter what, despite my print statements indicating that the value has changed. The other actions performed when tapping the heart work perfectly. I've been at it for hours. Any help would be appreciated. Thanks! import SwiftUI struct SearchView: View { @State private var searchText = "" @StateObject var save = SaveWords() @State var heart: String? @State var disappear = false @State var done = true var body: some View { NavigationView { VStack { if !disappear { SearchBarView(text: $searchText) Spacer() } if searchText != "" { List(.constant(Array(FetchWord.getWordFromStart(start: searchText)).prefix(10).map {Word(word: $0.1)})) { suggestion in NavigationLink(destination: suggestion.IPA.wrappedValue == "error" ? AnyView(EmptyView()) : AnyView(PracticeView(wordSheet: suggestion) .onAppear { disappear = true if done { SaveWords.file = "Favorites" DispatchQueue.main.async { Task { try? await save.load() heart = save.words.contains(suggestion.wrappedValue) ? ".fill" : "" } } } } .onDisappear { disappear = false Task { SaveWords.file = "History" try? await save.load() if save.words.first != suggestion.wrappedValue { save.words.insert(suggestion.wrappedValue, at: 0) try? await save.save() } } } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(action: { SaveWords.file = "Favorites" done = false if heart == "" { heart = ".fill" DispatchQueue.main.async { Task { try? await save.load() if !save.words.contains(suggestion.wrappedValue) { save.words.insert(suggestion.wrappedValue, at: 0) try? await save.save() } } } } else { heart = "" DispatchQueue.main.async { Task { try? await save.load() try? await save.delete(wordToDelete: suggestion.wrappedValue) try? await save.save() } } } done = true }, label: { Image(systemName: "heart" + (heart ?? "")) }) } }) ) { if suggestion.IPA.wrappedValue != "error" { CardView(wordSheet: suggestion) } } } } } Spacer() } } } #Preview { SearchView() }
Posted Last updated
.
Post not yet marked as solved
4 Replies
573 Views
Hello, Very recently, the following code has automatically appeared at the bottom of three of my SwiftUI View files: @available(iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *) struct $s10Accent_Ace33_0BADA584A03144EFDAB57154E6FD3FBALl7PreviewfMf_15PreviewRegistryfMu_: DeveloperToolsSupport.PreviewRegistry { static let fileID: String = "Accent_Ace/HistoryView.swift" static let line: Int = 47 static let column: Int = 1 static func makePreview() throws -> DeveloperToolsSupport.Preview { DeveloperToolsSupport.Preview { let randomWord1 = FetchWord.getRandomWord() let randomWord2 = FetchWord.getRandomWord() @State var randomWords = [Word(word: randomWord1.0, IPA: randomWord1.1, lineNumber: randomWord1.2), Word(word: randomWord2.0, IPA: randomWord2.1, lineNumber: randomWord2.2)] HistoryView(words: $randomWords) } } } This is from one of my files but it's very similar in the other two. It seems to have something to do with my previews. The problem is that this code generates an error: Ambiguous use of 'init(_:traits:body:)'. My previews worked just fine before the auto-generated code appeared, so I tried deleting it. However, it automatically comes back no matter how many times I get rid of it. It's preventing me from building my App Playground, so I can't run the app or even see the previews. Does anyone know how to get rid of it or fix the error? Thanks for the help!
Posted Last updated
.
Post marked as solved
2 Replies
469 Views
Hello, My App Playground uses a text file to work properly. I've had no issues running the app on Simulator, but it fails to find the file when being run on my physical iPhone. Has anyone had the same issue? Any idea what the problem is? Thanks for the help!
Posted Last updated
.