Add example plugin

Summary: Added example plugin for iOS, similar to android

Reviewed By: jknoxville

Differential Revision: D10492429

fbshipit-source-id: d639edc7a47ab240bb172516c2f38b8e2a9f285c
This commit is contained in:
Pritesh Nandgaonkar
2018-10-23 09:11:10 -07:00
committed by Facebook Github Bot
parent da37326a14
commit 74c1a24b86
5 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <Foundation/Foundation.h>
#import <FlipperKit/FlipperPlugin.h>
@interface FlipperKitExamplePlugin : NSObject<FlipperPlugin>
- (instancetype)init NS_UNAVAILABLE;
- (void)sendMessage:(NSString *)msg;
- (void)triggerNotification;
+ (instancetype) sharedInstance;
@end

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#if FB_SONARKIT_ENABLED
#import "FlipperKitExamplePlugin.h"
#import <FlipperKit/FlipperClient.h>
#import <FlipperKit/FlipperConnection.h>
#import <FlipperKit/FlipperResponder.h>
@interface FlipperKitExamplePlugin()
@property (strong, nonatomic) NSMutableArray<NSString *> *messagesToDisplay;
@property (strong, nonatomic) id<FlipperConnection> connection;
@property (nonatomic) NSInteger triggerCount;
@end
@implementation FlipperKitExamplePlugin
- (instancetype)init {
if (self = [super init]) {
_messagesToDisplay = @[].mutableCopy;
_triggerCount = 0;
}
return self;
}
+ (instancetype)sharedInstance {
static FlipperKitExamplePlugin *sInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sInstance = [FlipperKitExamplePlugin new];
});
return sInstance;
}
- (void)didConnect:(id<FlipperConnection>)connection {
__weak FlipperKitExamplePlugin *weakSelf = self;
self.connection = connection;
[connection receive:@"displayMessage" withBlock:^(NSDictionary *params, id<FlipperResponder> responder) {
[weakSelf.messagesToDisplay addObject:params[@"message"]];
}];
}
- (void)didDisconnect {
self.connection = nil;
}
- (NSString *)identifier {
return @"Example";
}
- (BOOL)runInBackground {
return YES;
}
- (void)sendMessage:(NSString *)msg {
[self.connection send:@"displayMessage" withParams:@{@"msg": msg}];
}
- (void)triggerNotification {
[self.connection send:@"triggerNotification" withParams:@{@"id": @(self.triggerCount)}];
self.triggerCount++;
}
@end
#endif