I try to create alarm app but I don't know how to set song from iTunes to sound of local notification.
Now I use this code to call iTunes
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
//[self presentModalViewController: picker animated: YES];
[self.navigationController pushViewController:picker animated:YES];
NSLog(@"gsudifghukdsf");
[picker release];
}
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self.navigationController popToRootViewControllerAnimated:YES];
//[self dismissModalViewControllerAnimated: YES];
NSLog(@"%@",mediaItemCollection);
UILocalNotification *local = [[UILocalNotification alloc] init];
//selectedSongCollection=mediaItemCollection;
}
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[self.navigationController popToRootViewControllerAnimated:YES];
//[self dismissModalViewControllerAnimated: YES];
}
and something about local notification look like this
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{ //NSLog(@"Get in if localNotif");
return;
}
localNotif.fireDate = DateAlarm;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = [NSString stringWithFormat:@"%@",DateAlarm];
// Set the action button
localNotif.alertAction = @"Oh Shit";
localNotif.soundName = UILocalNotificationDefaultSoundName;
So please guide me how can I set song to local sound ??
As noted by @thephatp, a notification (local or remote) can only trigger playback of sounds that are in the app bundle. I see no way around this.
@r3dsm0k3 asks in his comment how apps like Rise trigger playback of sounds that aren't in the app bundle. If I had to guess, I would say that Rise registers itself as an app requiring the
audio
background mode:This effectively means that Rise is allowed to stay running all the time. It's allowed to do so because it plays audio on behalf of the user. That it doesn't play audio 100% of the time doesn't appear to be a problem for Apple.
Rise may or may not use UILocalNotifications. Most likely they only use these as a backup incase the app DOES get unloaded, and instead use another timer mechanism to trigger the wakeup alarm sequence.
You can only use sounds that are a part of the main bundle, meaning, they have be in the build of the app when submitted to the app store.
Yes, you can record sound, download sound, etc in app, but none of those sounds files created/saved can be used, because they are not in the app's bundle. If an app is using custom sounds by accessing them outside of the bundle, then they are using private APIs to do so. Trust me, I've tried every option I can think of.