I am having an aiff file of 5.0 seconds. I want to run it in loop up to 30 seconds. Please guide how could I do that.
Right now I am setting the notification in the normal way by the following code-
//Function to schedule local notification
-(void)schedulelocalnotification:(NSDate *)particularfiredate ringtone: (NSString *)particularringtone name:(NSString *)alarmname info:(NSDictionary *)dicttext
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = particularfiredate;
notification.soundName = [arrayAIFFFiles objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]];
notification.alertBody = alarmname;
notification.userInfo = dicttext;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
Please note that I don't want the notification banner and the notifications to appear 6 times, Just the sound should repeat up to 30 seconds.
If I am not doing this, And adding a sound file of 30 seconds, then the sound is continuous till 30 seconds, If the user closes the notification in between, and opens the app, The sound continues to play.That issue has been stated here : The UILocalNotification sound does not stop playing
I fixed it by creating multiple notifications at regular intervals which will be the duration of the track. Following is my code :
-(void)schedulelocalnotification:(NSDate *)particularfiredate ringtone: (NSString *)particularringtone name:(NSString *)alarmname info:(NSDictionary *)dicttext
{//post one single notification here with alert body, so that there are no multiple banners for each notification.
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = particularfiredate;
notification.soundName = [arrayAIFFFiles objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]];
notification.alertBody = alarmname;
notification.userInfo = dicttext;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
totalDuration = totalDuration + [[arraySoundDuration objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]]floatValue];
while (totalDuration<30) {//while time is less than 30 secs, which is the desired time.
NSDate *newDate1 = [particularfiredate dateByAddingTimeInterval:totalDuration];
UILocalNotification *notification1 = [[UILocalNotification alloc] init];
notification1.fireDate = newDate1;
notification1.soundName = [arrayAIFFFiles objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]];
// notification1.alertBody = alarmname;//create notification without alert body, just with the sound file, so there are no multiple banners.
notification1.userInfo = dicttext;
[[UIApplication sharedApplication] scheduleLocalNotification:notification1];
totalDuration = totalDuration + [[arraySoundDuration objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]]floatValue];
}
totalDuration = 0;
}
Related
UILocalNotification *soundNotification = [[UILocalNotification alloc] init];
soundNotification.repeatInterval = NSCalendarUnitMinute;
soundNotification.soundName = #"alarm.mp3";
soundNotification.fireDate = [NSDate date];
soundNotification.timeZone = [NSTimeZone defaultTimeZone];
soundNotification.alertBody = #"alarm is ringing"; //commenting out this line stop callback.
[[UIApplication sharedApplication] scheduleLocalNotification:soundNotification];
The problem is that I don't want to define an alertBody for a notification. But still hit the callback
- (void)application:(UIApplication*)application didReceiveLocalNotification:(nonnull UILocalNotification *)notification
Because If I don't hit the callback the sound of the notification cannot be stopped even if you call
- (void)cancelLocalNotification:(UILocalNotification *)notification;
Is there a way to stop UILocalNotification sound without defining alertBody for the notification?
I am developing iPhone App Using PJSIP. When i enters background mode,if i receive any call.
I am displaying UILocalNotification alert as:
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSString *alertBody = [NSString stringWithFormat:#"NEW VOIP CALL"];
notification.alertBody =alertBody;
notification.alertAction = #"Answer";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
But this alert dismiss after some 4 or 5 seconds.
how to make it repeat for some more time?
The best way in your circumstances is to specify a sound to play - this can be up to 30 seconds long. This seems to keep the notification displayed for the length of the sound:
UILocalNotification *notification =[[UILocalNotification alloc] init];
NSString *alertBody = [NSString stringWithFormat:#"NEW VOIP CALL"];
notification.alertBody =alertBody;
notification.alertAction = #"Answer";
notification.soundName = #"56 Alarm Bell.mp3";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
Solution 1:You need to Execute UIlaocationNotification Using Timer.
Solution 2: You Start Execute Notification when finish Previous notification.
I want to schedule local notification in my game.
First notification will come two hours after game play has ended.
After that another one come in the next 24 hours if still no gameplay. If gameplay resets to after 2 hours, then every 24 hrs until they enter game.
I would be very thankful to you if you can help me.
Here is my code:
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.alertBody = [self.notifyArray objectAtIndex:index];
NSTimeInterval sec = 7200;
notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:sec];
notif.repeatInterval = NSDayCalendarUnit;
notif.soundName = UILocalNotificationDefaultSoundName;
NSLog(#"notif : %u",notif.repeatInterval);
notif.applicationIconBadgeNumber += 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
//notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:20];
//[[UIApplication sharedApplication] scheduleLocalNotification:notif];
Try to debug first by checking the scheduled notifications list. You can see this thread for details iOS find list of Local Notification the app has already set
First give an 'identifier' to your local notification. Then and when app goes to background, use that identifier to identify notification from scheduled notifications of your application. And reschedule it after 2 hours , with repeat interval of day.
UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
if ( oneEvent.identifier = yourNotificationIdentifier){
//Reschedule oneEvent.
}
}
In my app I have objects that trigger Local Notifications.
When the app is in the background the Local Notifications are fired when it's their time to be fired, and that works fine.
For some reason, the Badge Number is not updated.
When setting the Notification object, I use the following code:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = obj.noteMeDate; //obj is an object for which the notification is created...
localNotification.alertBody = [NSString stringWithFormat:#"Note: %#", obj.title];
localNotification.alertAction = #"Show Me";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; //this is NOT WORKING...
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Anyone?
You can't increase the badge number, you can only set it to a certain number. At the time you're scheduling the notification, applicationIconBadgeNumber is 0 (since you're running the application in the foreground), thus every notification is showing only 1 in the badge.
Technically you cannot increment the badge icon directly but there is a way.
int num = [UIApplication sharedApplication].applicationIconBadgeNumber;
[UIApplication sharedApplication].applicationIconBadgeNumber = num + 1;
I need to send a text message when the current time equals the time selected in the UIDatePicker. How might I do this? You don't need to include the code to send the message, I already have that coded. I've tried all sorts of things with NSTimer and if - then statements but none have worked.
Edit: Since I wrote this question I've found a better way to do things. I just need to set a local notification and when received execute my code with -(void)didRevieveLocalNotification. Here is what I have so that any googlers can hopefully be helped.
NSDate *pickerDate = [self.datePicker date];
//Set Local Notification
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = pickerDate;
notif.timeZone = [NSTimeZone defaultTimeZone];
//----------------------------------------------------------------------
notif.alertBody = #"Tap to send your text message!";
notif.alertAction = #"send message...";
notif.soundName = #"sms_alert_nova.caf";
notif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
well i would use a local notification... something like this
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = theDate //The date that your picker has selected
notification.alertBody = #"Hey, the time just expired!"
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
Then in your AppDelegate
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
//Code to manage the notification logic
}
Hope this helps, the user will get the alert even if on background.. if on background the user must click the alert to let your application know that the local notification triggered, if he does (or he is on your app already, then the app delegate method will trigger letting your app know that the notification fired...
Hope this helps!