mirror of https://github.com/oxen-io/session-ios
Add custom ringtone sounds.
parent
cd32895657
commit
a44a117612
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
typedef NS_ENUM(NSUInteger, NotificationSound) {
|
||||
NotificationSound_Default = 0,
|
||||
NotificationSound_Aurora,
|
||||
NotificationSound_Bamboo,
|
||||
NotificationSound_Chord,
|
||||
NotificationSound_Circles,
|
||||
NotificationSound_Complete,
|
||||
NotificationSound_Hello,
|
||||
NotificationSound_Input,
|
||||
NotificationSound_Keys,
|
||||
NotificationSound_Note,
|
||||
NotificationSound_Popcorn,
|
||||
NotificationSound_Pulse,
|
||||
NotificationSound_Synth,
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class TSThread;
|
||||
|
||||
@interface NotificationSounds : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (NSArray<NSNumber *> *)allNotificationSounds;
|
||||
|
||||
+ (NSString *)displayNameForNotificationSound:(NotificationSound)notificationSound;
|
||||
|
||||
+ (NSString *)filenameForNotificationSound:(NotificationSound)notificationSound;
|
||||
|
||||
+ (void)playNotificationSound:(NotificationSound)notificationSound;
|
||||
|
||||
+ (NotificationSound)globalNotificationSound;
|
||||
+ (void)setGlobalNotificationSound:(NotificationSound)notificationSound;
|
||||
|
||||
+ (NotificationSound)notificationSoundForThread:(TSThread *)thread;
|
||||
+ (void)setNotificationSound:(NotificationSound)notificationSound forThread:(TSThread *)thread;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,226 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NotificationSounds.h"
|
||||
#import <AudioToolbox/AudioServices.h>
|
||||
#import <SignalServiceKit/TSStorageManager.h>
|
||||
#import <SignalServiceKit/TSThread.h>
|
||||
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
|
||||
|
||||
NSString *const kNotificationSoundsStorageNotificationCollection = @"kNotificationSoundsStorageNotificationCollection";
|
||||
NSString *const kNotificationSoundsStorageGlobalNotificationKey = @"kNotificationSoundsStorageGlobalNotificationKey";
|
||||
|
||||
@interface NotificationSounds ()
|
||||
|
||||
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
|
||||
|
||||
@property (nonatomic) NSMutableDictionary<NSNumber *, NSNumber *> *systemSoundIDMap;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation NotificationSounds
|
||||
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
static NotificationSounds *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] initDefault];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)initDefault
|
||||
{
|
||||
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
||||
|
||||
return [self initWithStorageManager:storageManager];
|
||||
}
|
||||
|
||||
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
OWSAssert(storageManager);
|
||||
|
||||
_dbConnection = storageManager.newDatabaseConnection;
|
||||
|
||||
OWSSingletonAssert();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSArray<NSNumber *> *)allNotificationSounds
|
||||
{
|
||||
return @[
|
||||
@(NotificationSound_Aurora),
|
||||
@(NotificationSound_Bamboo),
|
||||
@(NotificationSound_Chord),
|
||||
@(NotificationSound_Circles),
|
||||
@(NotificationSound_Complete),
|
||||
@(NotificationSound_Hello),
|
||||
@(NotificationSound_Input),
|
||||
@(NotificationSound_Keys),
|
||||
@(NotificationSound_Note),
|
||||
@(NotificationSound_Popcorn),
|
||||
@(NotificationSound_Pulse),
|
||||
@(NotificationSound_Synth),
|
||||
];
|
||||
}
|
||||
|
||||
+ (NSString *)displayNameForNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
// TODO: Should we localize these sound names?
|
||||
switch (notificationSound) {
|
||||
case NotificationSound_Aurora:
|
||||
return @"Aurora";
|
||||
case NotificationSound_Bamboo:
|
||||
return @"Bamboo";
|
||||
case NotificationSound_Chord:
|
||||
return @"Chord";
|
||||
case NotificationSound_Circles:
|
||||
return @"Circles";
|
||||
case NotificationSound_Complete:
|
||||
return @"Complete";
|
||||
case NotificationSound_Hello:
|
||||
return @"Hello";
|
||||
case NotificationSound_Input:
|
||||
return @"Input";
|
||||
case NotificationSound_Keys:
|
||||
return @"Keys";
|
||||
case NotificationSound_Default:
|
||||
case NotificationSound_Note:
|
||||
return @"Note";
|
||||
case NotificationSound_Popcorn:
|
||||
return @"Popcorn";
|
||||
case NotificationSound_Pulse:
|
||||
return @"Pulse";
|
||||
case NotificationSound_Synth:
|
||||
return @"Synth";
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSString *)filenameForNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
// TODO: Should we localize these sound names?
|
||||
switch (notificationSound) {
|
||||
case NotificationSound_Aurora:
|
||||
return @"aurora.m4r";
|
||||
case NotificationSound_Bamboo:
|
||||
return @"bamboo.m4r";
|
||||
case NotificationSound_Chord:
|
||||
return @"chord.m4r";
|
||||
case NotificationSound_Circles:
|
||||
return @"circles.m4r";
|
||||
case NotificationSound_Complete:
|
||||
return @"complete.m4r";
|
||||
case NotificationSound_Hello:
|
||||
return @"hello.m4r";
|
||||
case NotificationSound_Input:
|
||||
return @"input.m4r";
|
||||
case NotificationSound_Keys:
|
||||
return @"keys.m4r";
|
||||
case NotificationSound_Default:
|
||||
case NotificationSound_Note:
|
||||
return @"note.m4r";
|
||||
case NotificationSound_Popcorn:
|
||||
return @"popcorn.m4r";
|
||||
case NotificationSound_Pulse:
|
||||
return @"pulse.m4r";
|
||||
case NotificationSound_Synth:
|
||||
return @"synth.m4r";
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSURL *)soundURLForNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
NSString *filename = [self filenameForNotificationSound:notificationSound];
|
||||
|
||||
NSURL *_Nullable url = [[NSBundle mainBundle] URLForResource:filename.stringByDeletingPathExtension
|
||||
withExtension:filename.pathExtension];
|
||||
OWSAssert(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
+ (void)playNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
[self.sharedManager playNotificationSound:notificationSound];
|
||||
}
|
||||
|
||||
- (SystemSoundID)systemSoundIDForNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
if (!self.systemSoundIDMap) {
|
||||
self.systemSoundIDMap = [NSMutableDictionary new];
|
||||
}
|
||||
NSNumber *_Nullable systemSoundID = self.systemSoundIDMap[@(notificationSound)];
|
||||
if (!systemSoundID) {
|
||||
NSURL *soundURL = [NotificationSounds soundURLForNotificationSound:notificationSound];
|
||||
SystemSoundID newSystemSoundID;
|
||||
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, &newSystemSoundID);
|
||||
if (error) {
|
||||
OWSFail(@"%@ could not load sound.", self.logTag);
|
||||
}
|
||||
systemSoundID = @(newSystemSoundID);
|
||||
self.systemSoundIDMap[@(notificationSound)] = systemSoundID;
|
||||
}
|
||||
return (SystemSoundID)systemSoundID.unsignedIntegerValue;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)playNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
SystemSoundID systemSoundID = [self systemSoundIDForNotificationSound:notificationSound];
|
||||
AudioServicesPlayAlertSound(systemSoundID);
|
||||
}
|
||||
|
||||
+ (NotificationSound)defaultNotificationSound
|
||||
{
|
||||
return NotificationSound_Note;
|
||||
}
|
||||
|
||||
+ (NotificationSound)globalNotificationSound
|
||||
{
|
||||
NotificationSounds *notificationSounds = NotificationSounds.sharedManager;
|
||||
NSNumber *_Nullable value =
|
||||
[notificationSounds.dbConnection objectForKey:kNotificationSoundsStorageGlobalNotificationKey
|
||||
inCollection:kNotificationSoundsStorageNotificationCollection];
|
||||
// Default to the global default.
|
||||
return (value ? (NotificationSound)value.intValue : [self defaultNotificationSound]);
|
||||
}
|
||||
|
||||
+ (void)setGlobalNotificationSound:(NotificationSound)notificationSound
|
||||
{
|
||||
NotificationSounds *notificationSounds = NotificationSounds.sharedManager;
|
||||
[notificationSounds.dbConnection setObject:@(notificationSound)
|
||||
forKey:kNotificationSoundsStorageGlobalNotificationKey
|
||||
inCollection:kNotificationSoundsStorageNotificationCollection];
|
||||
}
|
||||
|
||||
+ (NotificationSound)notificationSoundForThread:(TSThread *)thread
|
||||
{
|
||||
NotificationSounds *notificationSounds = NotificationSounds.sharedManager;
|
||||
NSNumber *_Nullable value =
|
||||
[notificationSounds.dbConnection objectForKey:thread.uniqueId
|
||||
inCollection:kNotificationSoundsStorageNotificationCollection];
|
||||
// Default to the "global" notification sound, which in turn will default to the global default.
|
||||
return (value ? (NotificationSound)value.intValue : [self globalNotificationSound]);
|
||||
}
|
||||
|
||||
+ (void)setNotificationSound:(NotificationSound)notificationSound forThread:(TSThread *)thread
|
||||
{
|
||||
NotificationSounds *notificationSounds = NotificationSounds.sharedManager;
|
||||
[notificationSounds.dbConnection setObject:@(notificationSound)
|
||||
forKey:thread.uniqueId
|
||||
inCollection:kNotificationSoundsStorageNotificationCollection];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
typedef NS_ENUM(NSUInteger, OWSSound) {
|
||||
OWSSound_Default = 0,
|
||||
// Notification Sounds
|
||||
OWSSound_Aurora,
|
||||
OWSSound_Bamboo,
|
||||
OWSSound_Chord,
|
||||
OWSSound_Circles,
|
||||
OWSSound_Complete,
|
||||
OWSSound_Hello,
|
||||
OWSSound_Input,
|
||||
OWSSound_Keys,
|
||||
OWSSound_Note,
|
||||
OWSSound_Popcorn,
|
||||
OWSSound_Pulse,
|
||||
OWSSound_Synth,
|
||||
// Ringtone Sounds
|
||||
OWSSound_Apex,
|
||||
OWSSound_Beacon,
|
||||
OWSSound_Bulletin,
|
||||
OWSSound_By_The_Seaside,
|
||||
OWSSound_Chimes,
|
||||
OWSSound_Circuit,
|
||||
OWSSound_Constellation,
|
||||
OWSSound_Cosmic,
|
||||
OWSSound_Crystals,
|
||||
OWSSound_Hillside,
|
||||
OWSSound_Illuminate,
|
||||
OWSSound_Night_Owl,
|
||||
OWSSound_Opening,
|
||||
OWSSound_Playtime,
|
||||
OWSSound_Presto,
|
||||
OWSSound_Radar,
|
||||
OWSSound_Radiate,
|
||||
OWSSound_Ripples,
|
||||
OWSSound_Sencha,
|
||||
OWSSound_Signal,
|
||||
OWSSound_Silk,
|
||||
OWSSound_Slow_Rise,
|
||||
OWSSound_Stargaze,
|
||||
OWSSound_Summit,
|
||||
OWSSound_Twinkle,
|
||||
OWSSound_Uplift,
|
||||
OWSSound_Waves,
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class TSThread;
|
||||
|
||||
@interface OWSSounds : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (NSString *)displayNameForSound:(OWSSound)sound;
|
||||
|
||||
+ (NSString *)filenameForSound:(OWSSound)sound;
|
||||
|
||||
+ (void)playSound:(OWSSound)sound;
|
||||
|
||||
#pragma mark - Notifications
|
||||
|
||||
+ (NSArray<NSNumber *> *)allNotificationSounds;
|
||||
|
||||
+ (OWSSound)globalNotificationSound;
|
||||
+ (void)setGlobalNotificationSound:(OWSSound)sound;
|
||||
|
||||
+ (OWSSound)notificationSoundForThread:(TSThread *)thread;
|
||||
+ (void)setNotificationSound:(OWSSound)sound forThread:(TSThread *)thread;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,377 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSSounds.h"
|
||||
#import <AudioToolbox/AudioServices.h>
|
||||
#import <SignalServiceKit/TSStorageManager.h>
|
||||
#import <SignalServiceKit/TSThread.h>
|
||||
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
|
||||
|
||||
NSString *const kOWSSoundsStorageNotificationCollection = @"kOWSSoundsStorageNotificationCollection";
|
||||
NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlobalNotificationKey";
|
||||
|
||||
@interface OWSSounds ()
|
||||
|
||||
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
|
||||
|
||||
@property (nonatomic) NSMutableDictionary<NSNumber *, NSNumber *> *systemSoundIDMap;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSSounds
|
||||
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
static OWSSounds *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] initDefault];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)initDefault
|
||||
{
|
||||
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
||||
|
||||
return [self initWithStorageManager:storageManager];
|
||||
}
|
||||
|
||||
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
OWSAssert(storageManager);
|
||||
|
||||
_dbConnection = storageManager.newDatabaseConnection;
|
||||
// TODO: Is it safe to load all of these sounds into memory?
|
||||
// Probably better to do LRU cache.
|
||||
self.systemSoundIDMap = [NSMutableDictionary new];
|
||||
|
||||
OWSSingletonAssert();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSArray<NSNumber *> *)allNotificationSounds
|
||||
{
|
||||
return @[
|
||||
@(OWSSound_Aurora),
|
||||
@(OWSSound_Bamboo),
|
||||
@(OWSSound_Chord),
|
||||
@(OWSSound_Circles),
|
||||
@(OWSSound_Complete),
|
||||
@(OWSSound_Hello),
|
||||
@(OWSSound_Input),
|
||||
@(OWSSound_Keys),
|
||||
@(OWSSound_Note),
|
||||
@(OWSSound_Popcorn),
|
||||
@(OWSSound_Pulse),
|
||||
@(OWSSound_Synth),
|
||||
];
|
||||
}
|
||||
|
||||
+ (NSArray<NSNumber *> *)allRingtoneSounds
|
||||
{
|
||||
return @[
|
||||
@(OWSSound_Apex),
|
||||
@(OWSSound_Beacon),
|
||||
@(OWSSound_Bulletin),
|
||||
@(OWSSound_By_The_Seaside),
|
||||
@(OWSSound_Chimes),
|
||||
@(OWSSound_Circuit),
|
||||
@(OWSSound_Constellation),
|
||||
@(OWSSound_Cosmic),
|
||||
@(OWSSound_Crystals),
|
||||
@(OWSSound_Hillside),
|
||||
@(OWSSound_Illuminate),
|
||||
@(OWSSound_Night_Owl),
|
||||
@(OWSSound_Opening),
|
||||
@(OWSSound_Playtime),
|
||||
@(OWSSound_Presto),
|
||||
@(OWSSound_Radar),
|
||||
@(OWSSound_Radiate),
|
||||
@(OWSSound_Ripples),
|
||||
@(OWSSound_Sencha),
|
||||
@(OWSSound_Signal),
|
||||
@(OWSSound_Silk),
|
||||
@(OWSSound_Slow_Rise),
|
||||
@(OWSSound_Stargaze),
|
||||
@(OWSSound_Summit),
|
||||
@(OWSSound_Twinkle),
|
||||
@(OWSSound_Uplift),
|
||||
@(OWSSound_Waves),
|
||||
];
|
||||
}
|
||||
|
||||
+ (NSString *)displayNameForSound:(OWSSound)sound
|
||||
{
|
||||
// TODO: Should we localize these sound names?
|
||||
switch (sound) {
|
||||
case OWSSound_Default:
|
||||
OWSFail(@"%@ invalid argument.", self.logTag);
|
||||
return @"";
|
||||
|
||||
// Notification Sounds
|
||||
case OWSSound_Aurora:
|
||||
return @"Aurora";
|
||||
case OWSSound_Bamboo:
|
||||
return @"Bamboo";
|
||||
case OWSSound_Chord:
|
||||
return @"Chord";
|
||||
case OWSSound_Circles:
|
||||
return @"Circles";
|
||||
case OWSSound_Complete:
|
||||
return @"Complete";
|
||||
case OWSSound_Hello:
|
||||
return @"Hello";
|
||||
case OWSSound_Input:
|
||||
return @"Input";
|
||||
case OWSSound_Keys:
|
||||
return @"Keys";
|
||||
case OWSSound_Note:
|
||||
return @"Note";
|
||||
case OWSSound_Popcorn:
|
||||
return @"Popcorn";
|
||||
case OWSSound_Pulse:
|
||||
return @"Pulse";
|
||||
case OWSSound_Synth:
|
||||
return @"Synth";
|
||||
|
||||
// Ringtone Sounds
|
||||
case OWSSound_Apex:
|
||||
return @"Apex";
|
||||
case OWSSound_Beacon:
|
||||
return @"Beacon";
|
||||
case OWSSound_Bulletin:
|
||||
return @"Bulletin";
|
||||
case OWSSound_By_The_Seaside:
|
||||
return @"By The Seaside";
|
||||
case OWSSound_Chimes:
|
||||
return @"Chimes";
|
||||
case OWSSound_Circuit:
|
||||
return @"Circuit";
|
||||
case OWSSound_Constellation:
|
||||
return @"Constellation";
|
||||
case OWSSound_Cosmic:
|
||||
return @"Cosmic";
|
||||
case OWSSound_Crystals:
|
||||
return @"Crystals";
|
||||
case OWSSound_Hillside:
|
||||
return @"Hillside";
|
||||
case OWSSound_Illuminate:
|
||||
return @"Illuminate";
|
||||
case OWSSound_Night_Owl:
|
||||
return @"Night Owl";
|
||||
case OWSSound_Opening:
|
||||
return @"Opening";
|
||||
case OWSSound_Playtime:
|
||||
return @"Playtime";
|
||||
case OWSSound_Presto:
|
||||
return @"Presto";
|
||||
case OWSSound_Radar:
|
||||
return @"Radar";
|
||||
case OWSSound_Radiate:
|
||||
return @"Radiate";
|
||||
case OWSSound_Ripples:
|
||||
return @"Ripples";
|
||||
case OWSSound_Sencha:
|
||||
return @"Sencha";
|
||||
case OWSSound_Signal:
|
||||
return @"Signal";
|
||||
case OWSSound_Silk:
|
||||
return @"Silk";
|
||||
case OWSSound_Slow_Rise:
|
||||
return @"Slow Rise";
|
||||
case OWSSound_Stargaze:
|
||||
return @"Stargaze";
|
||||
case OWSSound_Summit:
|
||||
return @"Summit";
|
||||
case OWSSound_Twinkle:
|
||||
return @"Twinkle";
|
||||
case OWSSound_Uplift:
|
||||
return @"Uplift";
|
||||
case OWSSound_Waves:
|
||||
return @"Waves";
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSString *)filenameForSound:(OWSSound)sound
|
||||
{
|
||||
switch (sound) {
|
||||
case OWSSound_Default:
|
||||
OWSFail(@"%@ invalid argument.", self.logTag);
|
||||
return @"";
|
||||
|
||||
// Notification Sounds
|
||||
case OWSSound_Aurora:
|
||||
return @"aurora.m4r";
|
||||
case OWSSound_Bamboo:
|
||||
return @"bamboo.m4r";
|
||||
case OWSSound_Chord:
|
||||
return @"chord.m4r";
|
||||
case OWSSound_Circles:
|
||||
return @"circles.m4r";
|
||||
case OWSSound_Complete:
|
||||
return @"complete.m4r";
|
||||
case OWSSound_Hello:
|
||||
return @"hello.m4r";
|
||||
case OWSSound_Input:
|
||||
return @"input.m4r";
|
||||
case OWSSound_Keys:
|
||||
return @"keys.m4r";
|
||||
case OWSSound_Note:
|
||||
return @"note.m4r";
|
||||
case OWSSound_Popcorn:
|
||||
return @"popcorn.m4r";
|
||||
case OWSSound_Pulse:
|
||||
return @"pulse.m4r";
|
||||
case OWSSound_Synth:
|
||||
return @"synth.m4r";
|
||||
|
||||
// Ringtone Sounds
|
||||
case OWSSound_Apex:
|
||||
return @"Apex.m4r";
|
||||
case OWSSound_Beacon:
|
||||
return @"Beacon.m4r";
|
||||
case OWSSound_Bulletin:
|
||||
return @"Bulletin.m4r";
|
||||
case OWSSound_By_The_Seaside:
|
||||
return @"By The Seaside.m4r";
|
||||
case OWSSound_Chimes:
|
||||
return @"Chimes.m4r";
|
||||
case OWSSound_Circuit:
|
||||
return @"Circuit.m4r";
|
||||
case OWSSound_Constellation:
|
||||
return @"Constellation.m4r";
|
||||
case OWSSound_Cosmic:
|
||||
return @"Cosmic.m4r";
|
||||
case OWSSound_Crystals:
|
||||
return @"Crystals.m4r";
|
||||
case OWSSound_Hillside:
|
||||
return @"Hillside.m4r";
|
||||
case OWSSound_Illuminate:
|
||||
return @"Illuminate.m4r";
|
||||
case OWSSound_Night_Owl:
|
||||
return @"Night Owl.m4r";
|
||||
case OWSSound_Opening:
|
||||
return @"Opening.m4r";
|
||||
case OWSSound_Playtime:
|
||||
return @"Playtime.m4r";
|
||||
case OWSSound_Presto:
|
||||
return @"Presto.m4r";
|
||||
case OWSSound_Radar:
|
||||
return @"Radar.m4r";
|
||||
case OWSSound_Radiate:
|
||||
return @"Radiate.m4r";
|
||||
case OWSSound_Ripples:
|
||||
return @"Ripples.m4r";
|
||||
case OWSSound_Sencha:
|
||||
return @"Sencha.m4r";
|
||||
case OWSSound_Signal:
|
||||
return @"Signal.m4r";
|
||||
case OWSSound_Silk:
|
||||
return @"Silk.m4r";
|
||||
case OWSSound_Slow_Rise:
|
||||
return @"Slow Rise.m4r";
|
||||
case OWSSound_Stargaze:
|
||||
return @"Stargaze.m4r";
|
||||
case OWSSound_Summit:
|
||||
return @"Summit.m4r";
|
||||
case OWSSound_Twinkle:
|
||||
return @"Twinkle.m4r";
|
||||
case OWSSound_Uplift:
|
||||
return @"Uplift.m4r";
|
||||
case OWSSound_Waves:
|
||||
return @"Waves.m4r";
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSURL *)soundURLForSound:(OWSSound)sound
|
||||
{
|
||||
NSString *filename = [self filenameForSound:sound];
|
||||
NSURL *_Nullable url = [[NSBundle mainBundle] URLForResource:filename.stringByDeletingPathExtension
|
||||
withExtension:filename.pathExtension];
|
||||
OWSAssert(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
+ (void)playSound:(OWSSound)sound
|
||||
{
|
||||
[self.sharedManager playSound:sound];
|
||||
}
|
||||
|
||||
- (SystemSoundID)systemSoundIDForSound:(OWSSound)sound
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
NSNumber *_Nullable systemSoundID = self.systemSoundIDMap[@(sound)];
|
||||
if (!systemSoundID) {
|
||||
NSURL *soundURL = [OWSSounds soundURLForSound:sound];
|
||||
SystemSoundID newSystemSoundID;
|
||||
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, &newSystemSoundID);
|
||||
if (error) {
|
||||
OWSFail(@"%@ could not load sound.", self.logTag);
|
||||
}
|
||||
systemSoundID = @(newSystemSoundID);
|
||||
self.systemSoundIDMap[@(sound)] = systemSoundID;
|
||||
}
|
||||
return (SystemSoundID)systemSoundID.unsignedIntegerValue;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)playSound:(OWSSound)sound
|
||||
{
|
||||
SystemSoundID systemSoundID = [self systemSoundIDForSound:sound];
|
||||
AudioServicesPlayAlertSound(systemSoundID);
|
||||
}
|
||||
|
||||
#pragma mark - Notifications
|
||||
|
||||
+ (OWSSound)defaultNotificationSound
|
||||
{
|
||||
return OWSSound_Note;
|
||||
}
|
||||
|
||||
+ (OWSSound)globalNotificationSound
|
||||
{
|
||||
OWSSounds *instance = OWSSounds.sharedManager;
|
||||
NSNumber *_Nullable value = [instance.dbConnection objectForKey:kOWSSoundsStorageGlobalNotificationKey
|
||||
inCollection:kOWSSoundsStorageNotificationCollection];
|
||||
// Default to the global default.
|
||||
return (value ? (OWSSound)value.intValue : [self defaultNotificationSound]);
|
||||
}
|
||||
|
||||
+ (void)setGlobalNotificationSound:(OWSSound)sound
|
||||
{
|
||||
OWSSounds *instance = OWSSounds.sharedManager;
|
||||
[instance.dbConnection setObject:@(sound)
|
||||
forKey:kOWSSoundsStorageGlobalNotificationKey
|
||||
inCollection:kOWSSoundsStorageNotificationCollection];
|
||||
}
|
||||
|
||||
+ (OWSSound)notificationSoundForThread:(TSThread *)thread
|
||||
{
|
||||
OWSSounds *instance = OWSSounds.sharedManager;
|
||||
NSNumber *_Nullable value =
|
||||
[instance.dbConnection objectForKey:thread.uniqueId inCollection:kOWSSoundsStorageNotificationCollection];
|
||||
// Default to the "global" notification sound, which in turn will default to the global default.
|
||||
return (value ? (OWSSound)value.intValue : [self globalNotificationSound]);
|
||||
}
|
||||
|
||||
+ (void)setNotificationSound:(OWSSound)sound forThread:(TSThread *)thread
|
||||
{
|
||||
OWSSounds *instance = OWSSounds.sharedManager;
|
||||
[instance.dbConnection setObject:@(sound)
|
||||
forKey:thread.uniqueId
|
||||
inCollection:kOWSSoundsStorageNotificationCollection];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue