iOS5 local notification custom sound xcode iOS iPhone objective-c Xcode - objective-c

I am trying to set custom local notification sound like this:
UILocalNotification *notification = [UILocalNotification new];
notification.timeZone = [NSTimeZone systemTimeZone];
notification.fireDate = date;
notification.alertAction = #"123";
notification.alertBody = #"123";
//!!!
notification.soundName = #"Glass.aiff";
alarmID=[NSString stringWithFormat:#"%i", arrayAlarms.count];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmID forKey:#"id"];
notification.userInfo = infoDict;
notification.repeatInterval=NSWeekCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
But I hear only default sound. I am testing app on ios5. Great thanks for help in advance and sorry for my english.

Custom Notification sounds are restricted to less than 30 seconds. If your sound is longer than this iOS will play the default sound instead. Could this be your problem?
For more info see here. https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html
"Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead."

Check your syntax , its wrong. check with this,
notification.soundName = "Glass.aiff";

One can still use UILocalNotificationDefaultSoundName for default local notification sound.

notification.soundName = #"Glass.aiff";
That should work. Make sure the sound(Glass.aiff) is actually in your app’s bundle, and is under 30 seconds.We can't set a custom sound that not present in our app's bundle ie from Document folder etc.

Related

Recorded sound is not playing with CocosDenshion

I recording voice with AVAudioRecorder (with this tutorial http://www.tumblr.com/tagged/avaudiorecorder?before=1300075871 ) and then try to play recorded sound with CocosDenshion:
CDSoundEngine* soundEngine = [[CDSoundEngine alloc] init];
NSArray *defs = [NSArray arrayWithObjects: [NSNumber numberWithInt:1],nil];
[soundEngine defineSourceGroups:defs];
//......
[soundEngine loadBuffer:1 filePath:[recorder.url path]];
[soundEngine playSound:1 sourceGroupId:0 pitch:2.0f pan:0 gain:1.0f loop:NO];
This code works fine on simulator, but on device (iPad 2, iOS 5.1.1)- sound is not playing.
I'll try to play recorded sound with AVAudioPlayer - its playing fine, but I need to pitch sound and found thats using CocosDenshion is simplest way for that.
What settings or something other should I check or fix to play recorded sound?
Problem solved, first I've changed the way to create CDSoundEngine instance, to use CDAudioManager:
CDSoundEngine = [CDAudioManager sharedManager].soundEngine;
Then, before playing recorded sound set mode for CDAudioManager to kAMM_PlayAndRecord:
[CDAudionManager sharedManager] setMode:kAMM_PlayAndRecord];
And finally redirect AudioSession to speakerphone:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride),&audioRouteOverride);
and all worked fine.

Retrieve users ringtone library

I was wondering if there was a way to retrieve users ringtones or sounds. I am not interested in their music playlist but like 30 second clips of audio that could work for uilocalnotifications. Does anyone know how to do this? Thanks!
See this answer.
how to get the system ringtones programmingly in ios?
If you still want to fire an audio notification, this article should get you started.
It seems you can assign a filename to the soundName property, or pass UILocalNotificationDefaultSoundName for (what I would guess is) the user's selected notification sound.
- (void)scheduleNotificationWithItem:(ToDoItem *)item interval:(int)minutesBefore {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.soundName = UILocalNotificationDefaultSoundName;
...
[localNotif release];
}

How to set badges on app icon when app is in minimize mode?

When application is in minimize state and at the same time notifications come then badges should be see on app icon.
If a notification arrives and your application is not is foreground, the OS handles the notification.
Your notification can have a field badge that will make the OS update the badge. However, this means that the server than sends the notification must have a way of knowing which number should be the badge.
The notification body would look like this:
{
"aps" : {
"badge" : 9
}
}
Heres my solution. I needed to achieve the same thing in an app that I did. I had a queue of Downloads and wanted to use a Badge to show how many downloads were left, and keep updating it even while in the background. Basically my solution was, every time one of the downloads were completed I setup a UILocalNotification with a silent sound, and no message text. Simply just set the badge..As seen below..
- (void)queRequestFinished:(ASIHTTPRequest *)request {
self.inResourceCount -= 1; // Deducted 1 from the total count of downloads in queue.
Class cls = NSClassFromString(#"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [NSDate date]; // Schedule notification for now.
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.soundName = #"silence.caf";
notif.applicationIconBadgeNumber = inResourceCount; // Number you want displayed as Badge.
// This is where the magic happens, and actually changes your badge.
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
Id like to point out, that my scenrio may be different from yours. I was using ASIHTTPRequest library, which has support for continuing downloads while backgrounded, and the method above queRequestFinished: is called even while in the background. Hope this helps, if it does mark it as the answer :) .

Mac os app signing?

I want to use Mountain Lion's new feature Notification Center. In NSUserNotification.h I found lines saying:
// Use of these classes requires your application be signed.
What does that mean? Should I have an Apple developer account and certificate? I Use the classes like this in Console Application.
NSUserNotificationCenter * center = [NSUserNotificationCenter defaultUserNotificationCenter];
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = #"asdasdasdasd";
notification.informativeText = #"text text";
[center deliverNotification:notification];
But nothing really happens. How do I sign the app?
A 2 second google will lead you here: https://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html

EKAlarm will not set in iOS 5

I wrote the following snippet to create an event. Setting the alarm works fine in iOS 4, but in iOS 5 it doesn't get set.
Is this a bug or am I missing something?
EKCalendar *cal = [self.eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
event.calendar = cal;
// .......
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-3600];
event.alarms = [NSArray arrayWithObject:alarm];
// .......
I had the same error.
The problem seems that startDate shoudln't be the same as endDate... really silly iOS change!
It seems to be related to that's happening in this ticket: EventKit - App freezes when adding an EKEvent with 2 alarms (iOS 5).
If you take a look at the EventKit section in the iOS 5 changes from iOS 4.3 document, it mentions that some items are deprecated for EKEvent. The hierarchy has changed and a new abstract superclass has been added: EKCalendarItem.
Avoid manipulating the alarms array. You need to add the alarm to your event like this:
EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-300];
[event addAlarm:reminder];
This will add a reminder 5 minutes before the start time.