Swift| How To change the sound of Push notification to other system sound? - swift

I'm kind of stuck with this issue. I have a working Push Notification in my app, and i'm trying to let the user to choose his own sound (All sounds are from iPhone built in sounds - kind of 'whatsapp') for a specific push notification.
the Payload i'm getting is something like
aps: {
alert = Message Type 1;
badge = 1;
sound = "default";
}
now in my app the user has three types of Push Notification, and I let the user choose which ringtone/Sound he wants for a certain push, after he choose I've saved his choice in NSUserDefaults.
my problem is that I Don't know how override the default sound in my userInfo and make a new Notification with a different sound that I saved in the NSUserDefaults.
I did it easily on Java, but it's so different with Swift and the way it's work with IOS.
Would be grateful, If anyone can shade some light on the subject.

Related

Disable push notification sound whenever I want

Is there a way to disable the push notification sound - whenever the alert comes in.
Currently I am using a blank sound file to do this, but is there a way to disable the sound.
If you dont want to play sounds, you can register for remote notifications again for only alert notification type. If you want the sound should not be played on receiving the alert notification, you should not be sending the sound value in the notification payload sent from the notification server.
You specify a bitmask of notification types when you register for notifications. If you don't want a sound to be played when notifications come in, remove UIRemoteNotificationTypeSound from that bitmask:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge)];
Go to the preferences application and select "Notifications", select your app and turn off the sound.

view capturing in background

we can easily capture a view(screenshot) programmatically in iPhone.
But i am trying to capture screen automatically after every 5 seconds.that also, can be done.
But my main objective is , to capture screen, even if the app is closed, i.e in background.
Apple doesn't allow to background process to run for a long time, but can we do it for 5-10 min in background.
Capturing screen,even if the app is closed.Ofcourse user can close this function, within the app.
Apple might reject this, but is this possible ?
Regards
This is possible but it's not easy. You can register you app (via a .plist setting) as being a media app, this will allow it to run in the background. This is normally to allow media apps to continue playing music when the app is sent to the background. However if you are careful you can get it to do other thing in there too.
In your plist under "Required Background Modes" add a key "Item 0" and set it to "App plays Audio". This will mean you can do it.
You will then have to using AVAudioPlayer, play a silent sound that is say 5mins long, and then register one of your controllers for the AVPlayerItemDidPlayToEndTimeNotification notification. Then when this calls back, you can have your bit of code that, first takes a screenshot, and then starts the sound again.
This is the general concept, look somewhere like :
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/
for how to set up the audio playing.
Just a note: APPLE WILL REJECT THIS!
If you are making an app for personal use only, this is fine, but will never make it to the app store.
Hoep this sheds some light on your situation! :)

Sound in Push Notification iPhone

Is there any way to set (toogle on/off) your push notification alert (after registered to APNS), sound and badge (by Code) inside an application?
I'm sorry the question seems a little ambiguous, actually I want to know
Is it possible to non activate the sound and alert inside the application function (by code) I am working. It is similar as you can disable the sound, alert or badge in iPhone Settings, But I want to do it in code.
It is like Whatsapp app in iPhone, there are some notification setting — we can toggle the alert on or off.
You could make a system where the user can choose a sound. Save that one. And in the method where the push notification comes in. Play that sound. I dont know if this works when the phone is on sleep mode.

how can we implement a radio alarm in iphone?

I want to set alarm sound as selected radio streams for my app in iphone.
If any one knows this please help me.
THANKS in advance
You can schedule a local notification (alarm) that functions very similar to a "push notification". A dialog will be displayed, a static sound file can be played as well. If the user clicks "view" in the dialog, your app will open and you can start running code (i.e. load an audio stream).
So no, it's not really possible to load an audio stream from the network. You can KEEP streaming when you're in the background, but you can't START streaming.
You might be able to do it if your app was in the foreground, and the screen was just locked. But it wouldn't work if they left your app.

How do you send messages between two instances of a custom UITableViewCell?

I have a UITableView populated with a bunch of music players that I've made using a custom UITableViewCell. (as shown in the screenshot linked here: screenshot).
The problem with the way I have it coded is that since each cell is completely independent, there's no way for one tableviewcell to check if any other the other cells have audio playing. This means that when I run my app, I am able to play more than one audio file at the same time.
Ultimately, how would I go about putting some sort of check in place so that when the user hits the play button, the app first checks to see if any other cell is playing audio, and, if so, stops them before playing its own audio file?
Please let me know if you would like me to post my project.
Thank you!
For starters I can't think of any good reason the cells themselves should be responsible for playing the audio. They should be responsible for telling some other object (like whatever controller is responsible for the UITableView) to play the audio. That controller would obviously then know to stop whatever it was already playing before playing something else.
In general, it's not a great idea to be putting that much logic into a 'view.'
It would probably be easiest to use notifications (NSNotification and NSNotificationCenter).
Use a common notification name for starting and stopping.
MusicPlayerWillPlay
MusicPlayerWillStop
When you create each player, register for both notifications. Then when playerA is going to play, it posts a MusicPlayerWillPlay notification. playerB, playerC and playerD, will get this notification, and if they are playing, will stop.
One caveat is that each player is unaware of the others, so you have to register with a nil object, which means playerA will get it's own notification. So in your notification method, you'll probably want to do something like
{
//...
if (sender == self)
return;
//...
}