EMCDDeviceManager+Remind.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /************************************************************
  2. * * Hyphenate CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of Hyphenate Inc.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from Hyphenate Inc.
  11. */
  12. #import "EMCDDeviceManager+Remind.h"
  13. void EMSystemSoundFinishedPlayingCallback(SystemSoundID sound_id, void* user_data)
  14. {
  15. AudioServicesDisposeSystemSoundID(sound_id);
  16. }
  17. @implementation EMCDDeviceManager (Remind)
  18. // The system sound for a new message
  19. - (SystemSoundID)playNewMessageSound
  20. {
  21. // Path for the audio file
  22. NSURL *bundlePath = [[NSBundle mainBundle] URLForResource:@"EaseUIResource" withExtension:@"bundle"];
  23. NSURL *audioPath = [[NSBundle bundleWithURL:bundlePath] URLForResource:@"in" withExtension:@"caf"];
  24. SystemSoundID soundID;
  25. AudioServicesCreateSystemSoundID((__bridge CFURLRef)(audioPath), &soundID);
  26. // Register the sound completion callback.
  27. AudioServicesAddSystemSoundCompletion(soundID,
  28. NULL, // uses the main run loop
  29. NULL, // uses kCFRunLoopDefaultMode
  30. EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
  31. NULL // for user data, but we don't need to do that in this case, so we just pass NULL
  32. );
  33. AudioServicesPlaySystemSound(soundID);
  34. return soundID;
  35. }
  36. - (void)playVibration
  37. {
  38. // Register the sound completion callback.
  39. AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,
  40. NULL, // uses the main run loop
  41. NULL, // uses kCFRunLoopDefaultMode
  42. EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
  43. NULL // for user data, but we don't need to do that in this case, so we just pass NULL
  44. );
  45. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  46. }
  47. @end