As of iOS 5 we have access to MPNowPlayingInfoCenter to display info in the lockscreen and in the multimedia controls on the multitasking bar. I have an app that plays local audio files. I want to display info like the artist's name, the album and the artwork on the lockscreen with MPNowPlayingInfoCenter, but the only way to do this (As far as I know) is to use MPMusicPlayerController and get nowPlayingItem... The problem is that MPMusicPlayerController is used to play iPod Music only, and not locally stored files. Is there a way around this in iOS 5?
You can create your own NSDictionary and supply that to the MPNowPlayingInfoCenter.
NSArray *keys = [NSArray arrayWithObjects:MPMediaItemPropertyAlbumTitle, MPMediaItemPropertyArtist, ..., nil];
NSArray *values = [NSArray arrayWithObjects:#"Album", #"Artist", ..., nil];
NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
Related
I'm try to create the push notification on my app, and using this script paste on application didReceiceRemoteNotification function:
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
messageContent, #"alert",
#"Increment", #"badge",
nil];
PFPush *push = [[PFPush alloc] init];
[push setChannel:chatRoomName];
[push setData:data];
[push sendPushInBackground];
But, I just can show the push message, there are no badge number show on my app right corner.. what's causing the problem?
for setting badge number you need to refere below url. that will give your required ans.
change Badge and push notification in iPhone SDK
I want to record audio in my iPhone app and once the audio is recorded I want a dialog box to open which asks for the filename.
And then I want to save the audio with that filename into my app. How can I do so?
try using AVAudioPlayer and AVAudioRecorder classes for audio recording and playback.Initially you have to establish an audio session using AVAudio session class
AVAudioSession *audioS =[AVAudioSession sharedInstance];
[audioS setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioS setActive:YES error:&error];
NSURL *url = [NSURL fileURLWithPath:#"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 2],AVNumberOfChannelsKey,[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
and then initialize the recorder and player classes...Hope this helps
Look at Apple's SpeakHere sample app, available on their iOS developer site.
you can see this question How do I record audio on iPhone with AVAudioRecorder? , which is pretty similar to your question or watch this sample code from apple http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html
I have seen that in iOS 5, CoreBluetooth provides the capability to check if Bluetooth is disabled. From what I have seen of the documentation, it is clearly aimed at bluetooth peripheral use. However, I am attempting to check if bluetooth is on because I am using GameKit (GKPeerPickerController) that will search endlessly for bluetooth connections if it is not enabled, which is an issue.
I tried to do this like so:
CBCentralManager * manager = [[CBCentralManager alloc] init];
if (manager.state == CBCentralManagerStatePoweredOn ) {
//go ahead with GameKit
}
This does not work, and manager.state is always equal to null. What am I doing wrong here? Or alternatively, are there better ways to check the status of bluetooth on the iPhone?
EDIT: I don't want to call any private APIs because I will be submitting this app to the app store. I have edited my question title to clarify this.
Ok, I discovered that by doing this:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
NSMutableArray * discoveredPeripherals = [NSMutableArray new];
CBCentralManager * manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[manager scanForPeripheralsWithServices:discoveredPeripherals options:options];
[manager stopScan];
If bluetooth is off, the system will pop up an alert view which will offer the choice to turn bluetooth on. Otherwise, if it finds a peripheral it will call a corresponding delegate method, but if there is nothing in that implementation you don't need to worry about it.
You can find the answer of your question by this link. Check it out.
Edited
Have you checked out the Game Kit Framework reference?
According to Apple:
Game Kit offers your applications the ability to create Bluetooth
connections between two devices.
Edited
Then try this project. https://github.com/sergiomtzlosa/MultiContactsSelector-ios
I need to get out the 25 most Played Songs out from my iPod Library with my iPhone app. i am using a MPMediaQuery.
One solutions would be to loop through all tracks and them comparing by MPMediaItemPropertyAlbumTrackCount. But i think thats a bit unefficient. Is there a way to directly get the Most Played items playlist?
I think you are looking for MPMediaItemPropertyPlayCount not MPMediaItemPropertyAlbumTrackCount. MPMediaItemPropertyAlbumTrackCount is the track number of the song as it appears in its album.
MPMediaItemPropertyPlayCount unfortunately cannot be used for making queries with MPMediaQuery since it is a user-defined property.
Your best option is to store all the play counts in a database like Core Data when your app is opened for the first time and update it by registering for notifications when the user's library changes.
you can use NSSortDescriptor to sort the most played songs
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:MPMediaItemPropertyPlayCount ascending:NO];
NSArray *sortedSongsArray = [[everything items] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorter]];
I'm trying to implement OpenFeint in my Cocos2D iPhone game, but here's something weird that I didn't find how to solve.
Here's how OpenFeint looks like when I initialize it:
http://img842.imageshack.us/img842/8564/screenshot20100926at520.png
And here's the code of the initialization:
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], OpenFeintSettingDashboardOrientation,
#"NAME", OpenFeintSettingShortDisplayName,
[NSNumber numberWithBool:NO], OpenFeintSettingEnablePushNotifications,
[NSNumber numberWithBool:YES], OpenFeintSettingAlwaysAskForApprovalInDebug,
[NSNumber numberWithBool:YES], OpenFeintSettingDisableUserGeneratedContent, nil];
[OpenFeint initializeWithProductKey:#"PRODUCTKEY" andSecret:#"SECRET"
andDisplayName:#"NAME" andSettings:settings andDelegates: [OFDelegatesContainer containerWithOpenFeintDelegate:self]];
[[CCDirector sharedDirector] runWithScene: [MainMenuScene node]];
I've seen your post in a few places as I was having the same problem as you were. I just figured out a potential solution for you and thought I would reply. It seems that on some occasions OpenFeint is unable to access the keywindow and in that case creates it's own window that may not act as yours has been set up to do. The solution is to let OpenFeint know specifically which window to go after by adding it to the settings. My settings are below and as you can see I added the "OpenFeintSettingPresentationWindow" Setting with my keyed window. After doing this it worked wonderfully. Hope this helps!
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], OpenFeintSettingDashboardOrientation,
window, OpenFeintSettingPresentationWindow,
#"ComingSoon", OpenFeintSettingShortDisplayName,
[NSNumber numberWithBool:YES], OpenFeintSettingEnablePushNotifications,
nil];
Chances are you have the wrong settings bundle for orientations in your binary, delete landscape and add the iPhone universal settings bundle.
I'm not sure specifically what the problem is, but it looks like OpenFeint is trying to display in landscape but is somehow being rotated as if it was in Portrait mode. Can oyu double check to make sure your orientations are correct for both your app's primary view controller (or however you configure it in Cocos2D). And that OpenFeint is aware of it as well?
In cocos2d,the window just need to refer to the window in applicationDidFinishLaunching.