Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

  • Loading branch information...
commit 71fcc597588e9a844800e0e17dad55124d1b36b8 0 parents
Jonatan Liljedahl authored October 16, 2012
13  AudioShareSDK.h
... ...
@@ -0,0 +1,13 @@
  1
+// AudioShareSDK.h
  2
+// Copyright (C)2012 Jonatan Liljedahl
  3
+
  4
+#import <Foundation/Foundation.h>
  5
+
  6
+@interface AudioShare : NSObject <UIAlertViewDelegate>
  7
+
  8
++ (AudioShare*) sharedInstance;
  9
+
  10
+- (BOOL) addSoundFromURL:(NSURL*)url withName:(NSString*)name;
  11
+- (BOOL) addSoundFromData:(NSData*)data withName:(NSString*)name;
  12
+
  13
+@end
75  AudioShareSDK.m
... ...
@@ -0,0 +1,75 @@
  1
+// AudioShareSDK.h
  2
+// Copyright (C)2012 Jonatan Liljedahl
  3
+
  4
+#import "AudioShareSDK.h"
  5
+#import <MobileCoreServices/UTCoreTypes.h>
  6
+
  7
+#define BM_CLIPBOARD_CHUNK_SIZE (5 * 1024 * 1024)
  8
+
  9
+@implementation AudioShare
  10
+
  11
++ (AudioShare*) sharedInstance {
  12
+    static AudioShare *a = nil;
  13
+    if(!a)
  14
+        a = [[AudioShare alloc] init];
  15
+    return a;
  16
+}
  17
+
  18
+- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
  19
+    if(buttonIndex != alertView.cancelButtonIndex) {
  20
+        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/app/audioshare-audio-document/id543859300?ls=1&mt=8"]];
  21
+    }
  22
+}
  23
+
  24
+- (BOOL)addSoundFromData:(NSData*)data withName:(NSString*)name {
  25
+    NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(
  26
+                                                                      NULL,
  27
+                                                                      (CFStringRef)name,
  28
+                                                                      NULL,
  29
+                                                                      (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
  30
+                                                                      CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
  31
+    name = [s autorelease];
  32
+    NSURL *asURL = [NSURL URLWithString:[NSString stringWithFormat:@"audiosharecmd://addFromPaste?%@",name]];
  33
+    if(![[UIApplication sharedApplication] canOpenURL:asURL]) {
  34
+        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"AudioShare"
  35
+                                                    message:@"AudioShare - audio document manager, version 2.1 or later is not installed on this device. You can get it on the App Store."
  36
+                                                   delegate:self
  37
+                                          cancelButtonTitle:@"Cancel"
  38
+                                          otherButtonTitles:@"Continue", nil];
  39
+        [a show];
  40
+        [a release];
  41
+        return NO;
  42
+    }
  43
+    UIPasteboard *board = [UIPasteboard generalPasteboard];
  44
+    if (!data) {
  45
+        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Sorry"
  46
+                                                    message:@"Something went wrong. Could not export audio!"
  47
+                                                   delegate:nil
  48
+                                          cancelButtonTitle:@"OK"
  49
+                                          otherButtonTitles:nil];
  50
+        [a show];
  51
+        [a release];
  52
+        return NO;
  53
+    }
  54
+    NSUInteger sz = [data length];
  55
+    NSUInteger chunkNumbers = (sz / BM_CLIPBOARD_CHUNK_SIZE) + 1;
  56
+    NSMutableArray *items = [NSMutableArray arrayWithCapacity:chunkNumbers];
  57
+    NSRange curRange;
  58
+    for (NSUInteger i = 0; i < chunkNumbers; i++) {
  59
+        curRange.location = i * BM_CLIPBOARD_CHUNK_SIZE;
  60
+        curRange.length = MIN(BM_CLIPBOARD_CHUNK_SIZE, sz - curRange.location);
  61
+        NSData *subData = [data subdataWithRange:curRange];
  62
+        NSDictionary *dict = [NSDictionary dictionaryWithObject:subData forKey:(NSString *)kUTTypeAudio];
  63
+        [items addObject:dict];
  64
+    }
  65
+    board.items = items;
  66
+    return [[UIApplication sharedApplication] openURL:asURL];
  67
+}
  68
+
  69
+- (BOOL)addSoundFromURL:(NSURL*)url withName:(NSString*)name {
  70
+    NSString *srcPath = [url path];
  71
+    NSData *dataFile = [NSData dataWithContentsOfMappedFile:srcPath];
  72
+    return [self addSoundFromData:dataFile withName:name];
  73
+}
  74
+
  75
+@end
48  README.md
Source Rendered
... ...
@@ -0,0 +1,48 @@
  1
+AudioShare SDK
  2
+==============
  3
+
  4
+This SDK will let you export audio to the AudioShare app for iPhone, iPad and iPod touch.
  5
+It can transfer soundfiles from memory or from file.
  6
+
  7
+AudioShare - audio document manager, is a simple tool to manage all your sounds in a single
  8
+place on your device, with easy transferring of sounds between AudioShare and other apps or
  9
+your computer. Read more about it here: http://kymatica.com/audioshare
  10
+
  11
+Usage
  12
+-----
  13
+
  14
+First, copy the files `AudioShareSDK.h` and `AudioShareSDK.m` into your project.
  15
+
  16
+The typical usage is to have a button or menu item labelled "Export to AudioShare" that
  17
+transfers a soundfile from your own app into AudioShare. Just put the following line in
  18
+the code that gets called when the user taps the button:
  19
+
  20
+    [[AudioShare sharedInstance] addSoundFromURL:theUrlToYourFile withName:@"My Sound"];
  21
+
  22
+In case you have your sound in memory, you can send an NSData instead:
  23
+
  24
+    [[AudioShare sharedInstance] addSoundFromData:yourSoundData withName:@"My Sound"];
  25
+
  26
+These methods will check that a recent enough version of AudioShare is installed, and otherwise
  27
+present the user with the option to view the app on the App Store. If AudioShare was installed,
  28
+it will open AudioShare and import the audio, and return YES if successfull.
  29
+
  30
+Don't forget to import the header:
  31
+
  32
+    #import "AudioShareSDK.h"
  33
+
  34
+Supported formats
  35
+-----------------
  36
+
  37
+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.
  38
+
  39
+License
  40
+-------
  41
+
  42
+You are free to incorporate this code in your own application, for the purpose of launching
  43
+and/or transferring sounds to the AudioShare app.
  44
+
  45
+If you do, I would appreciate if you drop me a message at lijon@kymatica.com
  46
+
  47
+Copyright (C)2012 Jonatan Liljedahl
  48
+http://kymatica.com

0 notes on commit 71fcc59

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