Skip to content

Instantly share code, notes, and snippets.

@jdewind
Created February 4, 2014 01:11
Show Gist options
  • Save jdewind/8795714 to your computer and use it in GitHub Desktop.
Save jdewind/8795714 to your computer and use it in GitHub Desktop.
@interface ApplicationDelegate<UIApplicationDelegate>
@end
@implementation ApplicationDelegate
- (RACSignal *)rac_registeredForRemoteNotifications {
RACSignal *signal = objc_getAssociatedObject(self, _cmd);
if (signal != nil) return signal;
RACSignal *didRegisterForRemoteNotification = [[self rac_signalForSelector: @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:) fromProtocol: @protocol(UIApplicationDelegate)] map: ^(RACTuple *tuple) {
return tuple.second;
}];
RACSignal *failedToRegister = [[self rac_signalForSelector: @selector(application:didFailToRegisterForRemoteNotificationsWithError:) fromProtocol: @protocol(UIApplicationDelegate)] flattenMap: ^(RACTuple *tuple) {
return [RACSignal error: tuple.second];
}];
signal = [RACSignal merge:@[didRegisterForRemoteNotification, failedToRegister]];
objc_setAssociatedObject(self, _cmd, signal, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return signal;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment