Objective-C Scripting Bridge and iTunes - objective-c

Hi i need a little help i want to include 2 buttons on my Mac App which will trigger 2 actions, 1 will trigger the iTunes shuffle feature and set it to YES but if it is all ready set to YES then it will set it to NO. The other will get iTunes current playback repeat mode.
This is what i have found from the iTunes.h file and also here's a description of the iTunes.h file http://merbist.com/2010/01/17/controlling-itunes-with-macruby/
#property BOOL shuffle; // play the songs in this playlist in random order?
#property iTunesERpt songRepeat; // playback repeat mode
Can anyone help me, thanks Sami.

You need to declare an instance of SBApplication to talk to iTunes:
SBApplication *_iTunes = [[SBApplication applicationWithBundleIdentifier: #"com.apple.itunes"] retain];
Once you have this SBApplication (keep it around in your class), use it to control iTunes directly. For example, to turn on the "Shuffle" mode:
_iTunes.currentPlaylist.shuffle = YES;
will do the trick.

Related

How to delete discovered bluetooth devices on ios 7?

I use BeeTee project for discover nearby bluetooth devices. Everything is good, but if it discovered a device its store this somewhere, and i cant find it again. If the device doesnt send bluetooth signal the bluetooth manager write this in log: BTM: lost device "device_name" device_address
How can i delete discovered devices?
They are stored in a dictionary:
#property (retain, nonatomic) NSMutableDictionary *currentAvailableDevices;
If you want to delete one of them, you can call the the delegate method
- (void)removeBluetoothDevice:(BluetoothDevice *)bluetoothDevice
{
[self.currentAvailableDevices removeObjectForKey:bluetoothDevice.address];
[self.tableView reloadData];
}
But are you sure that this approach makes sense?

MKMapView night mode like in iOS7 Apple Maps?

Is there an easy way to enable night mode on a MKMapView like the Apple Maps apps does when the sun is down ?
I didn't find such a thing the MapKit documentation.
Unfortunately it is a private api:
//add this above the interface of the class you want to try it on
#interface MKMapView ()
-(void) _setShowsNightMode:(BOOL)yesOrNo;
#end
//call this in your viewDidLoad or somewhere else appropriate
[self.mapView _setShowsNightMode:YES];
We should file a radar for apple to open this up to everyone. It could be a safety issue for people using maps in third party apps while driving. Your app will be rejected if you try and submit it to the app store using this.
No, you'd have to use a third-party library like Mapbox iOS SDK or MBXMapKit.

AvAudioPlayer with option to play in background

hello I am trying to make an app, with a "switch" where it can set that AvAudioPlayer object will play or not audiofile in backgorund.
Does exist a way to change this mode, in oder to choose as option to play an audiofile with AvAudioplayer in background?
I mean Pragrammatically and then during RUNTIME.
Thanks so much for you help
( and clear explanation )

Parse Starter Project for iPad

I know it's very vague and is asking a lot but does anyone know how to convert the standard iOS starter project from iPhone to iPad (both is best)? Or does anyone know where I can download one. I am a new iOS developer and am trying to start learning with Parse.
I am referring to this project https://www.parse.com/downloads/ios/parse-starter-project/latest
P.S. Just because this question isn't perfect doesn't mean you have to go and down vote and flag it for removal I don't have a lot of points already no need to lose even more :)
Not being able to see this sample project, it's hard to say for certain what it will take.
At bare minimum go into your project summary, and select "Universal" for the device support.
Above and beyond that, it just depends on what the app is and how it's structured. For NIBs, you will want a NIB for iPhone and one for iPad. I find it easy to abstract this away so that I can simplify my view loading:
MyController *myController = [[MyController alloc] initWithView:#"MyControllerView" bundle:nil];
Then in a category, I'd define initWithView similar to:
#implementation UIViewController (Universal)
-(id) initWithView:(NSString *)view bundle:(NSBundle *)nibBundle{
bool isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
NSString *nibName = [NSString stringWithFormat:#"%#_%#", view, (isIpad ? #"iPad" : #"iPhone")];
return [self initWithNibName:nibName bundle:nibBundle];
}
#end
But, that's just one aspect of supporting both devices. In reality the subject is rather specific to the app you're working on. Things like OS support (e.g., am I only targeting iOS 6 or higher) play a factor in things.
I have solved it now, if anyone needs the files email me turboecreations#iCloud.com I would upload them but I dont want my MediaFire and other accounts to be removed if I run into copyright issues.

Receive remote control events without audio

Here is some background information, otherwise skip ahead to the question in bold. I am building an app and I would like it to have access to the remote control/lock screen events. The tricky part is that this app does not play audio itself, it controls the audio of another device nearby. The communication between devices is not a problem when the app is in the foreground. As I just found out, an app does not assume control of the remote controls until it has played audio with a playback audio session, and was the last do so. This presents a problem because like I said, the app controls ANOTHER device's audio and has no need to play its own.
My first inclination is to have the app play a silent clip every time it is opened in order to assume control of the remote controls. The fact that I have to do this makes me wonder if I am even going to be allowed to do it by Apple or if there is another way to achieve this without fooling the system with fake audio clips.
QUESTION(S): Will Apple approve an app that plays a silent audio clip in order to assume control of the remote/lock screen controls for the purpose of controlling another device's audio? Is there any way of assuming control of the remote controls without an audio session?
P.S. I would prefer to have this functionality on iOS 4.0 and up.
P.P.S I have seen this similar question and it has gotten me brainstorming but the answer provided is not specific to what I need to know.
NOTE: As of iOS 7.1, you should be using MPRemoteCommandCenter instead of the answer below.
You create various system-provided subclasses of MPRemoteCommand and assign them to properties of the [MPRemoteCommandCenter sharedCommandCenter].
I'm keeping the rest of this around for historical reference, but the following is not guaranteed to work on recent iOS versions. In fact, it just might not.
You definitely do need an audio player but not necessarily an explicit session to take control of the remote control events. (AVAudioSession is implicit to any app that plays audio.) I spent a decent amount of time playing with this to confirm this.
I've seen a lot of confusion on the internet about where to set up the removeControlEventRecievedWithEvent: method and various approaches to the responder chain. I know this method works on iOS 6 and iOS 7. Other methods have not. Don't waste your time handling remote control events in the app delegate (where they used to work) or in a view controller which may go away during the lifecycle of your app.
I made a demo project to show how to do this.
Here's a quick rundown of what has to happen:
You need to create a subclass of UIApplication. When the documentation says UIResponder, it means UIApplication, since your application class is a subclass of UIResponder. In this subclass, you're going to implement the remoteControlReceivedWithEvent: and canBecomeFirstResponder methods. You want to return YES from canBecomeFirstResponder. In the remote control method, you'll probably want to notify your audio player that something's changed.
You need to tell iOS to use your custom class to run the app, instead of the default UIApplication. To do so, open main.m and change this:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RCAppDel`egate class]));
to look like this:
return UIApplicationMain(argc, argv, NSStringFromClass([RCApplication class]), NSStringFromClass([RCAppDelegate class]));
In my case RCApplication is the name of my custom class. Use the name of your subclass instead. Don't forget to #import the appropriate header.
OPTIONAL: You should configure an audio session. It's not required, but if you don't, audio won't play if the phone is muted. I do this in the demo app's delegate, but do so where appropriate.
Play something. Until you do, the remote controls will ignore your app. I just took an AVPlayer and gave it the URL of a streaming site that I expect to be up. If you find that it fails, put your own URL in there and play with it to your heart's content.
This example has a little bit more code in there to log out remote events, but it's not all that complicated. I just define and pass around some string constants.
I bet that a silent looping MP3 file would help work towards your goal.
Moshe's solution worked great for me! However one issue I noticed is when you paused the audio, the media controls would go away and you won't be able to play it again without going back into the app. If you set the Media Info on the lock screen when you play the audio then this won't happen:
NSDictionary *mediaInfo = #{MPMediaItemPropertyTitle: #"My Title",
MPMediaItemPropertyAlbumTitle: #"My Album Name",
MPMediaItemPropertyPlaybackDuration: [NSNumber numberWithFloat:0.30f]};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];