Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Push notification play sounds other than in Bundle

jamisonjamison Posts: 47Registered Users
edited March 2010 in iOS SDK Development
Guys

Has anyone worked out a way of getting push notifications to play sounds from a source other than the application bundle? Specifically the applications Documents directory.

My app can create its own sounds and I want the user to be able to assign this sound to be the one used for push notifications. Hence I can't ship pre-installed with the bundle.

I've tried saving files into the bundle within the app, but of course you get permission denied. (On the phone, not in the simulator).
Post edited by jamison on
· ·

Replies

  • Duncan CDuncan C Posts: 9,082Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited March 2010
    jamison wrote: »
    Guys

    Has anyone worked out a way of getting push notifications to play sounds from a source other than the application bundle? Specifically the applications Documents directory.

    My app can create its own sounds and I want the user to be able to assign this sound to be the one used for push notifications. Hence I can't ship pre-installed with the bundle.

    I've tried saving files into the bundle within the app, but of course you get permission denied. (On the phone, not in the simulator).

    I play simple sounds using the AVAudioPlayer class.

    You can create an AVAudioPlayer with the initializer initWithContentsOfURL.

    You just need to build a URL that points to a file in your documents directory.

    First, get the path to the documents directory, with code like this:
    NSString* userDocumentsPath = nil;
    	
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    if ([paths count] > 0) 
       userDocumentsPath = [paths objectAtIndex:0];
    

    Then append the filename to that string and turn it into a URL with the NSURL initializer initFileURLWithPath.

    Once you've created a sound player, just invoke it from the code that processes your push notification.


    Regards,

    Duncan C
    WareTo
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
    · ·
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,561Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    edited March 2010
    I'm guessing he means if the app isn't running.

    iPhone Dev Center: Apple Push Notification Service Programming Guide: Apple Push Notification Service

    Sounds like it needs to be in the bundle.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn - Professional iOS App Development. Available for hire.

    SlickShopper 2 | Leave a PayPal donation

    Free Xcode Tools: NSLog Utility | Getter Utility
    GitHub Projects: BTIKit | BTICoreDataKit

    Are you a newbie? Things you should read:
    Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
    · ·
  • jamisonjamison Posts: 47Registered Users
    edited March 2010
    Thanks for the response.

    Yes, I mean if the app is not running.

    That pretty much confirms my fears - teaches me a lesson in developing loads based on what the simulator did, only to find out the bundle is read only on the phone...

    doh! slaps head. again.

    Can't see any reason why they couldn't open this up though, to allow the push to play sounds in the apps Documents/ area.
    · ·
Sign In or Register to comment.