Skip to content

Instantly share code, notes, and snippets.

@crespoxiao
Forked from jdewind/ApplicationDelegateRAC.m
Last active August 29, 2015 14:26
Show Gist options
  • Save crespoxiao/a7ad821aee1b22d7be32 to your computer and use it in GitHub Desktop.
Save crespoxiao/a7ad821aee1b22d7be32 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