Skip to content
Browse files

Add sound alert class for easy system alerts.

  • Loading branch information...
1 parent 62daa9d commit 9d72db0439068886532a2608f641236629a83bfd @devinross committed Mar 10, 2014
View
8 src/TapkuLibrary.xcodeproj/project.pbxproj
@@ -47,6 +47,8 @@
20A2A521174C37870058571F /* TKSlideToUnlockView.m in Sources */ = {isa = PBXBuildFile; fileRef = 20A2A51F174C37870058571F /* TKSlideToUnlockView.m */; };
20C0354F17C9A5DD009EBB33 /* TKGlowButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 20C0354D17C9A5DD009EBB33 /* TKGlowButton.h */; };
20C0355017C9A5DD009EBB33 /* TKGlowButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 20C0354E17C9A5DD009EBB33 /* TKGlowButton.m */; };
+ 20C3592118CE5C0700530279 /* TKSoundAlertController.h in Headers */ = {isa = PBXBuildFile; fileRef = 20C3591F18CE5C0700530279 /* TKSoundAlertController.h */; };
+ 20C3592218CE5C0700530279 /* TKSoundAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = 20C3592018CE5C0700530279 /* TKSoundAlertController.m */; };
20CE10C41860A6A500249216 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20CE10C21860A62B00249216 /* XCTest.framework */; };
20DAFB031814BAAC00EF525B /* TKRetroButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 20DAFB011814BAAC00EF525B /* TKRetroButton.h */; };
20DAFB041814BAAC00EF525B /* TKRetroButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 20DAFB021814BAAC00EF525B /* TKRetroButton.m */; };
@@ -200,6 +202,8 @@
20A2A51F174C37870058571F /* TKSlideToUnlockView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKSlideToUnlockView.m; sourceTree = "<group>"; };
20C0354D17C9A5DD009EBB33 /* TKGlowButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKGlowButton.h; sourceTree = "<group>"; };
20C0354E17C9A5DD009EBB33 /* TKGlowButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKGlowButton.m; sourceTree = "<group>"; };
+ 20C3591F18CE5C0700530279 /* TKSoundAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKSoundAlertController.h; sourceTree = "<group>"; };
+ 20C3592018CE5C0700530279 /* TKSoundAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKSoundAlertController.m; sourceTree = "<group>"; };
20CE10C21860A62B00249216 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
20DAFB011814BAAC00EF525B /* TKRetroButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKRetroButton.h; sourceTree = "<group>"; };
20DAFB021814BAAC00EF525B /* TKRetroButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKRetroButton.m; sourceTree = "<group>"; };
@@ -574,6 +578,8 @@
3BF9A832159791EA002A7F9E /* TKShapeView.m */,
2026B5591748257B00447F22 /* TKTextView.h */,
2026B55A1748257B00447F22 /* TKTextView.m */,
+ 20C3591F18CE5C0700530279 /* TKSoundAlertController.h */,
+ 20C3592018CE5C0700530279 /* TKSoundAlertController.m */,
3B345A6E142E4F870075E654 /* Network */,
);
name = Core;
@@ -680,6 +686,7 @@
3B560B7214574E30005FBDBF /* TKImageCache.h in Headers */,
3B819B5414601DC500EC0097 /* TKViewController.h in Headers */,
3BF9A833159791EA002A7F9E /* TKShapeView.h in Headers */,
+ 20C3592118CE5C0700530279 /* TKSoundAlertController.h in Headers */,
207DF656178761210091E898 /* UITextField+TKCategory.h in Headers */,
207DFF9215E1E3BE00A0BC2A /* NSDate+CalendarGrid.h in Headers */,
20DE9F4A168FA1EF00655BF8 /* NSObject+TKCategory.h in Headers */,
@@ -816,6 +823,7 @@
3B6EDDDE11547C1400E454DA /* TKWindow.m in Sources */,
3B6EDDE111547C1700E454DA /* NSString+TKCategory.m in Sources */,
3B6EDDE411547C1D00E454DA /* NSDate+TKCategory.m in Sources */,
+ 20C3592218CE5C0700530279 /* TKSoundAlertController.m in Sources */,
3B6EDDEA11547C2700E454DA /* TKCalendarMonthViewController.m in Sources */,
202DD0CC188EF01200D5541E /* TKAlertViewController.m in Sources */,
3B6EDDEE11547C2900E454DA /* TKCalendarMonthTableViewController.m in Sources */,
View
47 src/TapkuLibrary/TKSoundAlertController.h
@@ -0,0 +1,47 @@
+//
+// TKSoundAlertController.h
+// Created by Devin Ross on 3/10/14.
+//
+/*
+
+ tapku || http://github.com/devinross/tapkulibrary
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ */
+
+@import Foundation;
+@import AVFoundation;
+@import AudioToolbox;
+
+@interface TKSoundAlertController : NSObject <AVAudioPlayerDelegate>
+
++ (TKSoundAlertController*) sharedInstance;
+
+@property (assign,nonatomic) BOOL on;
+
+
++ (void) playAIF:(NSString*)soundName;
++ (void) playAIFF:(NSString*)soundName;
++ (void) playWAV:(NSString*)soundName;
+
+@end
View
85 src/TapkuLibrary/TKSoundAlertController.m
@@ -0,0 +1,85 @@
+//
+// TKSoundAlertController.m
+// Created by Devin Ross on 12/17/13.
+//
+/*
+
+ tapku || http://github.com/devinross/tapkulibrary
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ */
+
+#import "TKSoundAlertController.h"
+
+@interface TKSoundAlertController ()
+
+@property (nonatomic,strong) NSMutableDictionary *sounds;
+
+@end
+
+@implementation TKSoundAlertController
+
+
++ (TKSoundAlertController*)sharedInstance {
+ static TKSoundAlertController *instance = nil;
+ if (!instance) {
+ instance = [[TKSoundAlertController alloc] init];
+ }
+ return instance;
+}
+- (id) init{
+ if(!(self=[super init])) return nil;
+ self.sounds = [[NSMutableDictionary alloc] initWithCapacity:10];
+ return self;
+}
++ (void) playAIF:(NSString*)soundName {
+ [[TKSoundAlertController sharedInstance] playSoundName:soundName type:@"aif"];
+}
++ (void) playAIFF:(NSString*)soundName {
+ [[TKSoundAlertController sharedInstance] playSoundName:soundName type:@"aiff"];
+}
++ (void) playWAV:(NSString*)soundName {
+ [[TKSoundAlertController sharedInstance] playSoundName:soundName type:@"wav"];
+}
+- (void) playSoundName:(NSString*)soundName type:(NSString*)type{
+ if (!self.on)
+ return;
+
+ NSNumber *soundIDHolder = [self.sounds objectForKey:soundName];
+ if (soundIDHolder) {
+ SystemSoundID soundID = (SystemSoundID) [soundIDHolder unsignedLongValue];
+ AudioServicesPlaySystemSound(soundID);
+ } else {
+ NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:type];
+ if (path) {
+ NSURL *url = [NSURL fileURLWithPath:path];
+ SystemSoundID soundID = 0;
+ if (AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &soundID) == noErr) {
+ [self.sounds setObject:[NSNumber numberWithUnsignedLong:soundID] forKey:soundName];
+ AudioServicesPlaySystemSound(soundID);
+ }
+ }
+ }
+}
+
+@end
View
2 src/TapkuLibrary/TapkuLibrary.h
@@ -74,6 +74,8 @@
#import "TKShimmerLabel.h"
#import "TKReorderTableView.h"
+#import "TKSoundAlertController.h"
+
// CELLS
#import "TKLabelCell.h"
#import "TKLabelTextViewCell.h"

0 comments on commit 9d72db0

Please sign in to comment.
Something went wrong with that request. Please try again.