I am using PushToTalk in my project for using only listing audio.
steps :-
App Launch :- Create PTT Channel
PTT Token :- Send Token in Server
App Kill :- It's Automatically restored channel using :- channelDescriptor(restoredChannelUUID channelUUID: UUID) -> PTChannelDescriptor
Play audio given by incomingPushResult method
issue :-
I am receiving an audio link through incomingPushResult.
When incomingPushResult is called, it automatically restores the channel. However, the channel has already been created, resulting in two channels being created.
When I send the link from the server, the audio plays properly.
However, if I resend the same link after 5-6 seconds, the audio does not play.
After I leave the first channel, the same audio starts playing in the second channel. When I send the link again, the audio does not play because I left the first (main) channel.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
Task {
await self.createChannel()
}
return true
}
func createChannel() async {
do {
channelManager = try await PTChannelManager.channelManager(delegate: self, restorationDelegate: self)
let channelImage = UIImage(named: "ic_p")
channelDescriptor = PTChannelDescriptor(name: "Pikachu", image: channelImage)
let channelUUID = UUID()
self.currentChannelUUID = channelUUID
channelManager?.requestJoinChannel(channelUUID: channelUUID, descriptor: channelDescriptor!)
print("PTT creating channel")
} catch {
print("Error creating channel: \(error)")
}
}
func incomingPushResult(channelManager: PTChannelManager, channelUUID: UUID, pushPayload: [String : Any]) -> PTPushResult {
guard let data = pushPayload["data"] as? [String: Any],
let mediaLink = data["media_link"] as? String else {
return .leaveChannel
}
print("incomingPTT")
// URL to fetch the audio data from
self.audioURL = mediaLink
// Play the audio from the URL
DispatchQueue.main.async {
self.playSound(url: self.audioURL)
}
let participant = PTParticipant(name: mediaLink, image: .checkmark)
return .activeRemoteParticipant(participant)
}
func channelDescriptor(restoredChannelUUID channelUUID: UUID) -> PTChannelDescriptor {
let channelImage = UIImage(named: "ic_r")
return PTChannelDescriptor(name: "Restored Channel", image: channelImage)
}
func channelManager(_ channelManager: PTChannelManager, didActivate audioSession: AVAudioSession) {
print("Activated audio session")
self.playSound(url: self.audioURL)
}
Output: -
App Launch
After App Kill Play audio :- Audio Play Success and leave the channel
(Before Leave Channel View)
After Leave Channel View
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Is it possible to play audio in the Background or when the app is Terminated? If yes, how can I play audio in the Background or when the app is Terminated in iOS using Swift? I am receiving an audio link in a Firebase notification. How can I play this audio link when the app is in the Background or Terminated?
I am working on Agora Voice Call and using CallKit to manage incoming and outgoing calls.
Issue:
When I accept a call, CallKit goes behind my app. I want CallKit to remain in front of my app. Please guide me.
I am trying to add in-app purchases to my app. I created a StoreKit Configuration file and checked the option 'Sync this file with an app in App Store Connect' because I have already completed the subscription setup in my Apple Developer account.
I also tried implementing the in-app purchases directly without using the StoreKit Configuration file, but I’m getting an 'Invalid Product Identifiers' error. I’ve double-checked, and the product ID matches the one listed in my Apple account.
Please guide me on what I should do.
I’m facing an issue with In-App Purchases. I’ve completed the setup successfully. I logged in with User A's Apple account on an iPhone and completed a purchase. After that, I logged in with User B's account on the same iPhone. When I try to make the same purchase, I get the following error:
“Purchase is a duplicate and will not be reported.”
Because the purchase was already made using User A’s Apple ID, I’m unable to make the same purchase again using User B’s account on the same device.
Could you please guide me on how to handle this situation?
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Tags:
Subscriptions
StoreKit Test
App Store Connect
In-App Purchase