Skip to content

Instantly share code, notes, and snippets.

@joekr
Last active December 10, 2015 10:38
Show Gist options
  • Save joekr/4422453 to your computer and use it in GitHub Desktop.
Save joekr/4422453 to your computer and use it in GitHub Desktop.
Subscription With Block
@interface DataController : NSObject
- (void) getSubscriptionFromServer onComplete:(void (^)(void)) completionBlock
onCancelled:(void (^)(void)) cancelBlock;
@end
@interface DataController()
@property (nonatomic, copy) void (^onTransactionCancelled)();
@property (nonatomic, copy) void (^onTransactionCompleted)(SKPaymentTransaction *transaction);
@end
@implementation DataController
@synthesize onTransactionCancelled;
@synthesize onTransactionCompleted;
- (void) getSubscriptionFromServer onComplete:(void (^)(void)) completionBlock
onCancelled:(void (^)(void)) cancelBlock{
self.onTransactionCompleted = completionBlock;
self.onTransactionCancelled = cancelBlock;
[self getSubscription];
}
- (void) getSubscriptionFromServer {
// do some stuff if(success == ture){
if(success == true){
if(self.onTransactionCompleted){
self.onTransactionCompleted();
}
}else{
if(self.onTransactionCancelled){
self.onTransactionCancelled();
}
}
}
@end
- (void) findSubscription{
[myObject getSubscriptionFromServer onComplete:^ {
//Handle subscription call passed
}
onCancelled:^{
//Handle subscription call failed
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment