Skip to content

Commit 53fd68b

Browse files
committed
[ios] finalize for ringtone/ringback/busytone supports.
1 parent 9fefb42 commit 53fd68b

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

ios/RNInCallManager/RNInCallManager.swift

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -181,29 +181,24 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
181181
NSNotificationCenter.defaultCenter().removeObserver(observer, name: name, object: object)
182182
}
183183

184-
func getRingbackUri(_type: String) -> NSURL? {
185-
let fileBundle: String = "incallmanager_ringback"
186-
let fileBundleExt: String = "mp3"
187-
let fileSysWithExt: String = "vc~ringing.caf"
188-
let fileSysPath: String = "/System/Library/Audio/UISounds"
189-
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type)
190-
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleRingbackUri, &self.defaultRingbackUri)
191-
}
192-
193-
func startRingback(ringbackUriType: String) -> Void {
184+
// --- _ringbackUriType: never go here with be empty string.
185+
func startRingback(_ringbackUriType: String) -> Void {
194186
// you may rejected by apple when publish app if you use system sound instead of bundled sound.
195-
print("startRingback()")
187+
print("startRingback(): UriType=\(_ringbackUriType)")
196188
do {
197189
if self.mRingback != nil {
198190
if self.mRingback.playing {
191+
print("startRingback(): is already playing")
199192
return
200193
} else {
201194
self.stopRingback()
202195
}
203196
}
197+
// ios don't have embedded DTMF tone generator. use system dtmf sound files.
198+
let ringbackUriType: String = (_ringbackUriType == "_DTMF_" ? "_DEFAULT_" : _ringbackUriType)
204199
let ringbackUri: NSURL? = getRingbackUri(ringbackUriType)
205200
if ringbackUri == nil {
206-
print("no available ringback")
201+
print("startRingback(): no available ringback")
207202
return
208203
}
209204
//self.storeOriginalAudioSetup()
@@ -233,29 +228,25 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
233228
}
234229
}
235230

236-
func getBusytoneUri(_type: String) -> NSURL? {
237-
let fileBundle: String = "incallmanager_busytone"
238-
let fileBundleExt: String = "mp3"
239-
let fileSysWithExt: String = "ct-busy.caf" //ct-congestion.caf
240-
let fileSysPath: String = "/System/Library/Audio/UISounds"
241-
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type)
242-
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleBusytoneUri, &self.defaultBusytoneUri)
243-
}
244-
245-
func startBusytone(busytoneUriType: String) -> Bool {
231+
// --- _busytoneUriType: never go here with be empty string.
232+
func startBusytone(_busytoneUriType: String) -> Bool {
246233
// you may rejected by apple when publish app if you use system sound instead of bundled sound.
247-
print("startBusytone()")
234+
print("startBusytone(): UriType=\(_busytoneUriType)")
248235
do {
249236
if self.mBusytone != nil {
250237
if self.mBusytone.playing {
238+
print("startBusytone(): is already playing")
251239
return false
252240
} else {
253241
self.stopBusytone()
254242
}
255243
}
244+
245+
// ios don't have embedded DTMF tone generator. use system dtmf sound files.
246+
let busytoneUriType: String = (_busytoneUriType == "_DTMF_" ? "_DEFAULT_" : _busytoneUriType)
256247
let busytoneUri: NSURL? = getBusytoneUri(busytoneUriType)
257248
if busytoneUri == nil {
258-
print("no available busytone")
249+
print("startBusytone(): no available media")
259250
return false
260251
}
261252
//self.storeOriginalAudioSetup()
@@ -287,31 +278,26 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
287278
}
288279
}
289280

290-
func getRingtoneUri(_type: String) -> NSURL? {
291-
let fileBundle: String = "incallmanager_ringtone"
292-
let fileBundleExt: String = "mp3"
293-
let fileSysWithExt: String = "Opening.m4r" //Marimba.m4r
294-
let fileSysPath: String = "/Library/Ringtones"
295-
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type)
296-
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleRingtoneUri, &self.defaultRingtoneUri)
297-
}
298-
281+
// --- ringtoneUriType May be empty
299282
@objc func startRingtone(ringtoneUriType: String) -> Void {
300283
// you may rejected by apple when publish app if you use system sound instead of bundled sound.
301-
print("startRingtone()");
284+
print("startRingtone(): UriType=\(ringtoneUriType)")
302285
do {
303286
if self.mRingtone != nil {
304287
if self.mRingtone.playing {
288+
print("startRingtone(): is already playing.")
305289
return
306290
} else {
307291
self.stopRingtone()
308292
}
309293
}
310294
let ringtoneUri: NSURL? = getRingtoneUri(ringtoneUriType)
311295
if ringtoneUri == nil {
312-
print("no available ringtone")
296+
print("startRingtone(): no available media")
313297
return
314298
}
299+
300+
// --- ios has Ringer/Silent switch, so just play without check ringer volume.
315301
self.storeOriginalAudioSetup()
316302
self.mRingtone = try AVAudioPlayer(contentsOfURL: ringtoneUri!)
317303
self.mRingtone.delegate = self
@@ -339,6 +325,33 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
339325
}
340326
}
341327

328+
func getRingbackUri(_type: String) -> NSURL? {
329+
let fileBundle: String = "incallmanager_ringback"
330+
let fileBundleExt: String = "mp3"
331+
let fileSysWithExt: String = "vc~ringing.caf"
332+
let fileSysPath: String = "/System/Library/Audio/UISounds"
333+
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type) // --- you can't get default user perfrence sound in ios
334+
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleRingbackUri, &self.defaultRingbackUri)
335+
}
336+
337+
func getBusytoneUri(_type: String) -> NSURL? {
338+
let fileBundle: String = "incallmanager_busytone"
339+
let fileBundleExt: String = "mp3"
340+
let fileSysWithExt: String = "ct-busy.caf" //ct-congestion.caf
341+
let fileSysPath: String = "/System/Library/Audio/UISounds"
342+
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type) // --- you can't get default user perfrence sound in ios
343+
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleBusytoneUri, &self.defaultBusytoneUri)
344+
}
345+
346+
func getRingtoneUri(_type: String) -> NSURL? {
347+
let fileBundle: String = "incallmanager_ringtone"
348+
let fileBundleExt: String = "mp3"
349+
let fileSysWithExt: String = "Opening.m4r" //Marimba.m4r
350+
let fileSysPath: String = "/Library/Ringtones"
351+
let type = (_type == "" || _type == "_DEFAULT_" ? fileSysWithExt : _type) // --- you can't get default user perfrence sound in ios
352+
return self.getAudioUri(type, fileBundle, fileBundleExt, fileSysWithExt, fileSysPath, &self.bundleRingtoneUri, &self.defaultRingtoneUri)
353+
}
354+
342355
func getAudioUri(_type: String, _ fileBundle: String, _ fileBundleExt: String, _ fileSysWithExt: String, _ fileSysPath: String, inout _ uriBundle: NSURL!, inout _ uriDefault: NSURL!) -> NSURL? {
343356
var type = _type
344357
if type == "_BUNDLE_" {
@@ -358,11 +371,8 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
358371
if uriDefault == nil {
359372
let target: String = "\(fileSysPath)/\(type)"
360373
uriDefault = self.getSysFileUri(target)
361-
if uriDefault == nil {
362-
return nil
363-
}
364374
}
365-
return uriDefault;
375+
return uriDefault
366376
}
367377

368378
func getSysFileUri(target: String) -> NSURL? {
@@ -403,5 +413,3 @@ class RNInCallManager: NSObject, AVAudioPlayerDelegate {
403413
}
404414

405415
}
406-
407-

0 commit comments

Comments
 (0)