CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Apr 2015 |
Maintained by Florian Krüger.
This is a small cocoapod of the excellent SOAppDelegate idea by Nico Hämäläinen. After I used SOAppDelegate in some of my projects I quickly discovered that I didn't want to use Vanilla AppDelegates anymore. This pod should simplify the setup of new iOS projects.
To run the example project; clone the repo, and run pod install from the Example directory first.
See this blog post for a detailed writeup about this topic.
Make your UIAppDelegate implementation a subclass of SOXAppDelegate.
#import "SOXAppDelegate.h"
@interface SOXDAppDelegate : SOXAppDelegate
@endCreate your Service classes. You can either use a plain NSObject subclass for that purpose or a SOXService subclass.
NSObject subclasses should at least implement some form of Singleton pattern to prevent multiple instances of your services (there is only one UIApplicationDelegate per App and so should your services).
The SOXService implements the default Singleton pattern, the shared instance is available via sharedInstance.
Add the services method to your SOXAppDelegate subclass. We're assuming MyServiceClass to be the name of your service in this example:
#pragma mark - Services
- (NSArray *)services
{
static NSArray * _services;
static dispatch_once_t _onceTokenServices;
dispatch_once(&_onceTokenServices, ^{
_services = @[[MyServiceClass sharedInstance]];
});
return _services;
}Implement all UIAppDelegate methods necessary for your service in the service class. You don't need to declare the UIApplicationDelegate. Your SOXAppDelegate subclass will call all methods implemented by the service when they are called on the AppDelegate.
Don't forget to call the super within all UIApplicationDelegate methods inside your delegate. The baseclass will then make sure that all services which implement said method get notified.
By default, SOXAppDelegate doesn't implement the following methods:
- application:didReceiveRemoteNotification:fetchCompletionHandler:- application:performFetchWithCompletionHandler:These methods require additional setup in your Info.plist if you really want to use them. T prevent you from seeing warnings on the console when running the app (see issue #2) or iTunes from sending you E-Mail after you submitted your App (see issue #3) these methods are now excluded by define.
To make use of these methods, use one of the following defines (or both):
SOXAPPDELEGATE_BACKGROUNDMODE_FETCHSOXAPPDELEGATE_BACKGROUNDMODE_REMOTENOTIFICATION (for - application:didReceiveRemoteNotification:fetchCompletionHandler:)To enable one of the background modes you need to make use of the post install hook of cocoapods:
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
# enable UIBackgroundMode 'fetch'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'SOXAPPDELEGATE_BACKGROUNDMODE_FETCH=1']
# enable UIBackgroundMode 'remote-notification'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'SOXAPPDELEGATE_BACKGROUNDMODE_REMOTENOTIFICATION=1']
# enable both
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'SOXAPPDELEGATE_BACKGROUNDMODE_FETCH=1', 'SOXAPPDELEGATE_BACKGROUNDMODE_REMOTENOTIFICATION=1']
end
end
end
Remember to run pod install afterwards to trigger the post install hook.
Thx to johndpope for his answer demonstrating how to add GCC Preprocessor Definitions to cocoapods.
Florian Krüger, [email protected]
SOXAppDelegate is available under the MIT license. See the LICENSE file for more info.