From 890ada02810d6e204db4e8a96e935a9c774f9f77 Mon Sep 17 00:00:00 2001 From: Ricardo Naharro Date: Thu, 30 May 2013 10:16:09 +0200 Subject: [PATCH 01/20] - ARC support --- VolumeSnap.xcodeproj/project.pbxproj | 8 +- VolumeSnap/AppDelegate.m | 5 -- VolumeSnap/RBVolumeButtons.m | 23 +++-- VolumeSnap/ViewController.h | 9 +- VolumeSnap/ViewController.m | 85 +++++++++++-------- VolumeSnap/en.lproj/MainStoryboard.storyboard | 34 ++------ 6 files changed, 74 insertions(+), 90 deletions(-) diff --git a/VolumeSnap.xcodeproj/project.pbxproj b/VolumeSnap.xcodeproj/project.pbxproj index f3db87a..099c4a6 100644 --- a/VolumeSnap.xcodeproj/project.pbxproj +++ b/VolumeSnap.xcodeproj/project.pbxproj @@ -62,9 +62,6 @@ 70C2EB311475EF4F00751AE8 = { isa = PBXGroup; children = ( - 70C2EB611475FE4900751AE8 /* MediaPlayer.framework */, - 70C2EB5F1475F07400751AE8 /* AudioToolbox.framework */, - 70C2EB5D1475F03B00751AE8 /* CoreAudio.framework */, 70C2EB461475EF4F00751AE8 /* VolumeSnap */, 70C2EB3F1475EF4F00751AE8 /* Frameworks */, 70C2EB3D1475EF4F00751AE8 /* Products */, @@ -82,6 +79,9 @@ 70C2EB3F1475EF4F00751AE8 /* Frameworks */ = { isa = PBXGroup; children = ( + 70C2EB5F1475F07400751AE8 /* AudioToolbox.framework */, + 70C2EB611475FE4900751AE8 /* MediaPlayer.framework */, + 70C2EB5D1475F03B00751AE8 /* CoreAudio.framework */, 70C2EB401475EF4F00751AE8 /* UIKit.framework */, 70C2EB421475EF4F00751AE8 /* Foundation.framework */, 70C2EB441475EF4F00751AE8 /* CoreGraphics.framework */, @@ -264,6 +264,7 @@ 70C2EB5B1475EF4F00751AE8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "VolumeSnap/VolumeSnap-Prefix.pch"; INFOPLIST_FILE = "VolumeSnap/VolumeSnap-Info.plist"; @@ -275,6 +276,7 @@ 70C2EB5C1475EF4F00751AE8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "VolumeSnap/VolumeSnap-Prefix.pch"; INFOPLIST_FILE = "VolumeSnap/VolumeSnap-Info.plist"; diff --git a/VolumeSnap/AppDelegate.m b/VolumeSnap/AppDelegate.m index 8d3627a..5fec58c 100644 --- a/VolumeSnap/AppDelegate.m +++ b/VolumeSnap/AppDelegate.m @@ -12,11 +12,6 @@ @implementation AppDelegate @synthesize window = _window; -- (void)dealloc -{ - [_window release]; - [super dealloc]; -} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { diff --git a/VolumeSnap/RBVolumeButtons.m b/VolumeSnap/RBVolumeButtons.m index f070ec2..c414925 100644 --- a/VolumeSnap/RBVolumeButtons.m +++ b/VolumeSnap/RBVolumeButtons.m @@ -19,7 +19,7 @@ -(void)stopStealingVolumeButtonEvents; @property BOOL isStealingVolumeButtons; @property BOOL suspended; -@property (retain) UIView *volumeView; +@property (strong) UIView *volumeView; @end @@ -48,20 +48,20 @@ void volumeListenerCallback ( float volume = *volumePointer; - if( volume > [(RBVolumeButtons*)inClientData launchVolume] ) + if( volume > [(__bridge RBVolumeButtons*)inClientData launchVolume] ) { - [(RBVolumeButtons*)inClientData volumeUp]; + [(__bridge RBVolumeButtons*)inClientData volumeUp]; } - else if( volume < [(RBVolumeButtons*)inClientData launchVolume] ) + else if( volume < [(__bridge RBVolumeButtons*)inClientData launchVolume] ) { - [(RBVolumeButtons*)inClientData volumeDown]; + [(__bridge RBVolumeButtons*)inClientData volumeDown]; } } -(void)volumeDown { - AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, self); + AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, (__bridge void *)(self)); [[MPMusicPlayerController applicationMusicPlayer] setVolume:launchVolume]; @@ -76,7 +76,7 @@ -(void)volumeDown -(void)volumeUp { - AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, self); + AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, (__bridge void *)(self)); [[MPMusicPlayerController applicationMusicPlayer] setVolume:launchVolume]; @@ -137,7 +137,7 @@ -(void)startStealingVolumeButtonEvents } CGRect frame = CGRectMake(0, -100, 10, 0); - self.volumeView = [[[MPVolumeView alloc] initWithFrame:frame] autorelease]; + self.volumeView = [[MPVolumeView alloc] initWithFrame:frame]; [self.volumeView sizeToFit]; [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubview:self.volumeView]; @@ -192,7 +192,7 @@ -(void)stopStealingVolumeButtonEvents [[NSNotificationCenter defaultCenter] removeObserver:self]; } - AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, self); + AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, (__bridge void *)(self)); if( hadToLowerVolume ) { @@ -217,14 +217,11 @@ -(void)dealloc self.suspended = NO; [self stopStealingVolumeButtonEvents]; - self.upBlock = nil; - self.downBlock = nil; - [super dealloc]; } -(void)initializeVolumeButtonStealer { - AudioSessionAddPropertyListener(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, self); + AudioSessionAddPropertyListener(kAudioSessionProperty_CurrentHardwareOutputVolume, volumeListenerCallback, (__bridge void *)(self)); } @end diff --git a/VolumeSnap/ViewController.h b/VolumeSnap/ViewController.h index 87eb39d..f82f531 100644 --- a/VolumeSnap/ViewController.h +++ b/VolumeSnap/ViewController.h @@ -14,14 +14,11 @@ @interface ViewController : UIViewController { float launchVolume; - IBOutlet UILabel *counterLabel; - int counter; - RBVolumeButtons *_buttonStealer; } -@property (retain) RBVolumeButtons *buttonStealer; -- (IBAction)startStealing:(id)sender; -- (IBAction)stopStealing:(id)sender; +@property (strong) RBVolumeButtons *buttonStealer; + +- (IBAction)changeStealing:(id)sender; @end diff --git a/VolumeSnap/ViewController.m b/VolumeSnap/ViewController.m index 72312cf..0b1c599 100644 --- a/VolumeSnap/ViewController.m +++ b/VolumeSnap/ViewController.m @@ -13,52 +13,66 @@ #import "RBVolumeButtons.h" +@interface ViewController () + +@property (nonatomic, weak) IBOutlet UILabel *counterLabel; +@property (weak, nonatomic) IBOutlet UIButton *changeStealingButton; +@property (nonatomic, assign) NSUInteger counter; +@property (nonatomic, assign, getter = isStealing) BOOL stealing; + +@end + @implementation ViewController @synthesize buttonStealer = _buttonStealer; +@synthesize counterLabel = counterLabel; +@synthesize counter = counter; - (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Release any cached data, images, etc that aren't in use. + [super didReceiveMemoryWarning]; + // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { - [super viewDidLoad]; - counter = 0; - - self.buttonStealer = [[[RBVolumeButtons alloc] init] autorelease]; - self.buttonStealer.upBlock = ^{ - counter++; - [counterLabel setText:[NSString stringWithFormat:@"%i",counter]]; - }; - self.buttonStealer.downBlock = ^{ - counter--; - [counterLabel setText:[NSString stringWithFormat:@"%i",counter]]; - }; + [super viewDidLoad]; + [self.changeStealingButton setTitle:NSLocalizedString(@"Start stealing", nil) forState:UIControlStateNormal]; + + counter = 0; + + self.buttonStealer = [[RBVolumeButtons alloc] init]; + __weak typeof(self) weakSelf = self; + self.buttonStealer.upBlock = ^{ + weakSelf.counter++; + [weakSelf.counterLabel setText:[NSString stringWithFormat:@"%i", weakSelf.counter]]; + }; + self.buttonStealer.downBlock = ^{ + weakSelf.counter--; + [weakSelf.counterLabel setText:[NSString stringWithFormat:@"%i", weakSelf.counter]]; + }; } - (void)viewDidUnload { - [counterLabel release]; - counterLabel = nil; - self.buttonStealer = nil; - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; + counterLabel = nil; + self.buttonStealer = nil; + [self setChangeStealingButton:nil]; + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; } - (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; + [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; + [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated @@ -73,22 +87,25 @@ - (void)viewDidDisappear:(BOOL)animated - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - // Return YES for supported orientations - return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); + // Return YES for supported orientations + return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -- (void)dealloc { - [counterLabel release]; - [super dealloc]; -} -- (IBAction)startStealing:(id)sender +- (IBAction)changeStealing:(id)sender { - [self.buttonStealer startStealingVolumeButtonEvents]; + if ([self isStealing]) + { + [self.buttonStealer stopStealingVolumeButtonEvents]; + [self.changeStealingButton setTitle:NSLocalizedString(@"Start stealing", nil) forState:UIControlStateNormal]; + } + else + { + [self.buttonStealer startStealingVolumeButtonEvents]; + [self.changeStealingButton setTitle:NSLocalizedString(@"Stop stealing", nil) forState:UIControlStateNormal]; + } + + self.stealing = !self.stealing; } -- (IBAction)stopStealing:(id)sender -{ - [self.buttonStealer stopStealingVolumeButtonEvents]; -} @end diff --git a/VolumeSnap/en.lproj/MainStoryboard.storyboard b/VolumeSnap/en.lproj/MainStoryboard.storyboard index dac7e93..c550631 100644 --- a/VolumeSnap/en.lproj/MainStoryboard.storyboard +++ b/VolumeSnap/en.lproj/MainStoryboard.storyboard @@ -1,5 +1,5 @@ - + @@ -42,7 +42,7 @@ - @@ -76,23 +61,14 @@ - + + - - - - - - - - - - From 4d35d1a42abe519dbd0ffd701d00bc15fac87d34 Mon Sep 17 00:00:00 2001 From: Bitfinity Date: Fri, 9 Aug 2013 07:34:04 -0700 Subject: [PATCH 02/20] Create README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8967e5 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +RBVolumeButtons +=============== + +This lets you steal the volume up and volume down buttons on iOS. + + +ARC version From 929173e86155856630f0c848874705d5b7b802bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=A9=E8=BE=BA=E7=BE=85=E3=82=A8=E3=83=AB=E3=83=8D?= =?UTF-8?q?=E3=82=B9=E3=83=88?= Date: Mon, 25 Nov 2013 15:15:46 +0900 Subject: [PATCH 03/20] CocoaPods support --- RBVolumeButtons.podspec | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 RBVolumeButtons.podspec diff --git a/RBVolumeButtons.podspec b/RBVolumeButtons.podspec new file mode 100644 index 0000000..a771887 --- /dev/null +++ b/RBVolumeButtons.podspec @@ -0,0 +1,33 @@ + +Pod::Spec.new do |s| + + s.name = "RBVolumeButtons" + s.version = "0.0.1" + s.summary = "This lets you steal the volume up and volume down buttons on iOS." + s.homepage = "https://github.com/blladnar/RBVolumeButtons" + + s.license = { :type => 'Apache License, Version 2.0', :text => <<-LICENSE + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + LICENSE + } + s.author = { "Randall Brown" => "" } + + s.platform = :ios + s.requires_arc = false + + s.source = { :git => "https://github.com/blladnar/RBVolumeButtons.git", :commit => "5ac61f7ddcdfb35e5a8d6844617c9b9f2011587f" } + s.source_files = 'VolumeSnap/RBVolumeButtons.{h,m}' + + s.frameworks = 'AudioToolbox', 'MediaPlayer' + +end From 1c299b78fdee8fc2bed8a284d95c401c904cca9a Mon Sep 17 00:00:00 2001 From: Dominik Wagner Date: Tue, 10 Dec 2013 11:33:05 +0100 Subject: [PATCH 04/20] [CHANGE] disallowed rotation so demo app can be used sideways --- VolumeSnap/VolumeSnap-Info.plist | 2 -- 1 file changed, 2 deletions(-) diff --git a/VolumeSnap/VolumeSnap-Info.plist b/VolumeSnap/VolumeSnap-Info.plist index 2186129..64a0532 100644 --- a/VolumeSnap/VolumeSnap-Info.plist +++ b/VolumeSnap/VolumeSnap-Info.plist @@ -35,8 +35,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight From 1eda314d8481deba979256e458ee10c5055333e9 Mon Sep 17 00:00:00 2001 From: Dominik Wagner Date: Tue, 10 Dec 2013 11:33:22 +0100 Subject: [PATCH 05/20] [CHANGE] made the start stealing button bigger --- VolumeSnap/en.lproj/MainStoryboard.storyboard | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/VolumeSnap/en.lproj/MainStoryboard.storyboard b/VolumeSnap/en.lproj/MainStoryboard.storyboard index c550631..652c500 100644 --- a/VolumeSnap/en.lproj/MainStoryboard.storyboard +++ b/VolumeSnap/en.lproj/MainStoryboard.storyboard @@ -1,8 +1,8 @@ - + - - + + @@ -10,22 +10,22 @@ - + - +