diff --git a/iOS/FlipperKit.podspec b/iOS/FlipperKit.podspec index d414c72ed..7832e83cb 100644 --- a/iOS/FlipperKit.podspec +++ b/iOS/FlipperKit.podspec @@ -144,4 +144,13 @@ Pod::Spec.new do |spec| ss.source_files = "iOS/Plugins/FlipperKitUserDefaultsPlugin/**/*.{h,m}" ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" } end + + spec.subspec "FlipperKitExamplePlugin" do |ss| + ss.header_dir = "FlipperKitExamplePlugin" + ss.dependency 'FlipperKit/Core' + ss.compiler_flags = folly_compiler_flags + ss.public_header_files = 'iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin.h' + ss.source_files = "iOS/Plugins/FlipperKitExamplePlugin/**/*.{h,mm}" + ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" } + end end diff --git a/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.h b/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.h new file mode 100644 index 000000000..a2817e61f --- /dev/null +++ b/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.h @@ -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 +#import + +@interface FlipperKitExamplePlugin : NSObject + +- (instancetype)init NS_UNAVAILABLE; +- (void)sendMessage:(NSString *)msg; +- (void)triggerNotification; ++ (instancetype) sharedInstance; + +@end diff --git a/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.mm b/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.mm new file mode 100644 index 000000000..5c67fc57d --- /dev/null +++ b/iOS/Plugins/FlipperKitExamplePlugin/FlipperKitExamplePlugin/FlipperKitExamplePlugin.mm @@ -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 +#import +#import + +@interface FlipperKitExamplePlugin() +@property (strong, nonatomic) NSMutableArray *messagesToDisplay; +@property (strong, nonatomic) id 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)connection { + __weak FlipperKitExamplePlugin *weakSelf = self; + self.connection = connection; + [connection receive:@"displayMessage" withBlock:^(NSDictionary *params, id 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 diff --git a/iOS/Sample/AppDelegate.mm b/iOS/Sample/AppDelegate.mm index 18b59a63f..6db8d0acf 100644 --- a/iOS/Sample/AppDelegate.mm +++ b/iOS/Sample/AppDelegate.mm @@ -12,6 +12,7 @@ #import #import #import +#import #import #import @@ -39,6 +40,7 @@ [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; + [client addPlugin:[FlipperKitExamplePlugin sharedInstance]]; [client start]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; diff --git a/iOS/Sample/Podfile b/iOS/Sample/Podfile index 3204256c5..22e288af4 100644 --- a/iOS/Sample/Podfile +++ b/iOS/Sample/Podfile @@ -9,6 +9,7 @@ target 'Sample' do pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec' pod 'FlipperKit/SKIOSNetworkPlugin', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec' + pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec' pod 'Flipper', :path => '../../Flipper.podspec' post_install do |installer|