Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 71fcc597588e9a844800e0e17dad55124d1b36b8 @lijon committed Oct 16, 2012
Showing with 136 additions and 0 deletions.
  1. +13 −0 AudioShareSDK.h
  2. +75 −0 AudioShareSDK.m
  3. +48 −0 README.md
13 AudioShareSDK.h
@@ -0,0 +1,13 @@
+// AudioShareSDK.h
+// Copyright (C)2012 Jonatan Liljedahl
+
+#import <Foundation/Foundation.h>
+
+@interface AudioShare : NSObject <UIAlertViewDelegate>
+
++ (AudioShare*) sharedInstance;
+
+- (BOOL) addSoundFromURL:(NSURL*)url withName:(NSString*)name;
+- (BOOL) addSoundFromData:(NSData*)data withName:(NSString*)name;
+
+@end
75 AudioShareSDK.m
@@ -0,0 +1,75 @@
+// AudioShareSDK.h
+// Copyright (C)2012 Jonatan Liljedahl
+
+#import "AudioShareSDK.h"
+#import <MobileCoreServices/UTCoreTypes.h>
+
+#define BM_CLIPBOARD_CHUNK_SIZE (5 * 1024 * 1024)
+
+@implementation AudioShare
+
++ (AudioShare*) sharedInstance {
+ static AudioShare *a = nil;
+ if(!a)
+ a = [[AudioShare alloc] init];
+ return a;
+}
+
+- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
+ if(buttonIndex != alertView.cancelButtonIndex) {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/app/audioshare-audio-document/id543859300?ls=1&mt=8"]];
+ }
+}
+
+- (BOOL)addSoundFromData:(NSData*)data withName:(NSString*)name {
+ NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(
+ NULL,
+ (CFStringRef)name,
+ NULL,
+ (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
+ CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
+ name = [s autorelease];
+ NSURL *asURL = [NSURL URLWithString:[NSString stringWithFormat:@"audiosharecmd://addFromPaste?%@",name]];
+ if(![[UIApplication sharedApplication] canOpenURL:asURL]) {
+ UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"AudioShare"
+ message:@"AudioShare - audio document manager, version 2.1 or later is not installed on this device. You can get it on the App Store."
+ delegate:self
+ cancelButtonTitle:@"Cancel"
+ otherButtonTitles:@"Continue", nil];
+ [a show];
+ [a release];
+ return NO;
+ }
+ UIPasteboard *board = [UIPasteboard generalPasteboard];
+ if (!data) {
+ UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Sorry"
+ message:@"Something went wrong. Could not export audio!"
+ delegate:nil
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:nil];
+ [a show];
+ [a release];
+ return NO;
+ }
+ NSUInteger sz = [data length];
+ NSUInteger chunkNumbers = (sz / BM_CLIPBOARD_CHUNK_SIZE) + 1;
+ NSMutableArray *items = [NSMutableArray arrayWithCapacity:chunkNumbers];
+ NSRange curRange;
+ for (NSUInteger i = 0; i < chunkNumbers; i++) {
+ curRange.location = i * BM_CLIPBOARD_CHUNK_SIZE;
+ curRange.length = MIN(BM_CLIPBOARD_CHUNK_SIZE, sz - curRange.location);
+ NSData *subData = [data subdataWithRange:curRange];
+ NSDictionary *dict = [NSDictionary dictionaryWithObject:subData forKey:(NSString *)kUTTypeAudio];
+ [items addObject:dict];
+ }
+ board.items = items;
+ return [[UIApplication sharedApplication] openURL:asURL];
+}
+
+- (BOOL)addSoundFromURL:(NSURL*)url withName:(NSString*)name {
+ NSString *srcPath = [url path];
+ NSData *dataFile = [NSData dataWithContentsOfMappedFile:srcPath];
+ return [self addSoundFromData:dataFile withName:name];
+}
+
+@end
48 README.md
@@ -0,0 +1,48 @@
+AudioShare SDK
+==============
+
+This SDK will let you export audio to the AudioShare app for iPhone, iPad and iPod touch.
+It can transfer soundfiles from memory or from file.
+
+AudioShare - audio document manager, is a simple tool to manage all your sounds in a single
+place on your device, with easy transferring of sounds between AudioShare and other apps or
+your computer. Read more about it here: http://kymatica.com/audioshare
+
+Usage
+-----
+
+First, copy the files `AudioShareSDK.h` and `AudioShareSDK.m` into your project.
+
+The typical usage is to have a button or menu item labelled "Export to AudioShare" that
+transfers a soundfile from your own app into AudioShare. Just put the following line in
+the code that gets called when the user taps the button:
+
+ [[AudioShare sharedInstance] addSoundFromURL:theUrlToYourFile withName:@"My Sound"];
+
+In case you have your sound in memory, you can send an NSData instead:
+
+ [[AudioShare sharedInstance] addSoundFromData:yourSoundData withName:@"My Sound"];
+
+These methods will check that a recent enough version of AudioShare is installed, and otherwise
+present the user with the option to view the app on the App Store. If AudioShare was installed,
+it will open AudioShare and import the audio, and return YES if successfull.
+
+Don't forget to import the header:
+
+ #import "AudioShareSDK.h"
+
+Supported formats
+-----------------
+
+AudioShare supports all soundfile formats, bit depths and rates, that has built-in support in iOS: AIFF, AIFC, WAVE, SoundDesigner2, Next, MP3, MP2, MP1, AC3, AAC_ADTS, MPEG4, M4A, CAF, 3GP, 3GP2, AMR.
+
+License
+-------
+
+You are free to incorporate this code in your own application, for the purpose of launching
+and/or transferring sounds to the AudioShare app.
+
+If you do, I would appreciate if you drop me a message at lijon@kymatica.com
+
+Copyright (C)2012 Jonatan Liljedahl
+http://kymatica.com

0 comments on commit 71fcc59

Please sign in to comment.