Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
- (void)volumeUp {
if(self.upBlock) {
self.upBlock();
}
}
- (void)volumeDown {
if(self.upBlock) {
self.upBlock();
}
}
@interface UIApplication (Private)
- (void) setWantsVolumeButtonEvents: (BOOL)flag;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setWantsVolumeButtonEvents: YES];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:@"_UIApplicationVolumeDownButtonDownNotification"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
NSLog(@"Volume '-' event(down)");
}];
[center addObserverForName:@"_UIApplicationVolumeDownButtonUpNotification"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
NSLog(@"Volume '-' event (up)");
}];
[center addObserverForName:@"_UIApplicationVolumeUpButtonDownNotification"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
NSLog(@"Volume '+' event(down)");
}];
[center addObserverForName:@"_UIApplicationVolumeUpButtonUpNotification"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
NSLog(@"Volume '+' event (up)");
}];
return YES;
}
@synthesize upBlock = _upBlock;
@synthesize downBlock = _downBlock;
Как заставить внешние кнопки iPhone работать на себя