diff --git a/packages/shared-preferences/CHANGELOG.md b/packages/shared-preferences/CHANGELOG.md index 27a3a2769dd8..2807f717d465 100644 --- a/packages/shared-preferences/CHANGELOG.md +++ b/packages/shared-preferences/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.2.0] - 2017-05-10 + +* Upgrade to new plugin registration. (https://groups.google.com/forum/#!topic/flutter-dev/zba1Ynf2OKM) + ## [0.1.1] - 2017-05-09 * Upgrade Android SDK Build Tools to 25.0.3. diff --git a/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java b/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java index 14f96d427cca..b35175b7109f 100644 --- a/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java +++ b/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java @@ -4,13 +4,12 @@ package io.flutter.plugins.shared_preferences; +import android.app.Activity; import android.content.Context; -import io.flutter.app.FlutterActivity; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodCall; -import io.flutter.view.FlutterView; +import io.flutter.plugin.common.PluginRegistry; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -26,14 +25,15 @@ public class SharedPreferencesPlugin implements MethodCallHandler { private final android.content.SharedPreferences preferences; private final android.content.SharedPreferences.Editor editor; - public static SharedPreferencesPlugin register(FlutterActivity activity) { - return new SharedPreferencesPlugin(activity); + public static void registerWith(PluginRegistry.Registrar registrar) { + MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME); + SharedPreferencesPlugin instance = new SharedPreferencesPlugin(registrar.activity()); + channel.setMethodCallHandler(instance); } - private SharedPreferencesPlugin(FlutterActivity activity) { + private SharedPreferencesPlugin(Activity activity) { preferences = activity.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); editor = preferences.edit(); - new MethodChannel(activity.getFlutterView(), CHANNEL_NAME).setMethodCallHandler(this); } // Filter preferences to only those set by the flutter app. diff --git a/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java b/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java index d31984d2da0e..7abf1594572f 100644 --- a/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java +++ b/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java @@ -2,15 +2,13 @@ import android.os.Bundle; import io.flutter.app.FlutterActivity; -import io.flutter.plugins.PluginRegistry; +import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - PluginRegistry pluginRegistry; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - pluginRegistry = new PluginRegistry(); - pluginRegistry.registerAll(this); + GeneratedPluginRegistrant.registerWith(this); } } diff --git a/packages/shared-preferences/example/ios/Runner.xcodeproj/project.pbxproj b/packages/shared-preferences/example/ios/Runner.xcodeproj/project.pbxproj index 8defe23721e6..ff53f0910c1c 100644 --- a/packages/shared-preferences/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/shared-preferences/example/ios/Runner.xcodeproj/project.pbxproj @@ -7,10 +7,11 @@ objects = { /* Begin PBXBuildFile section */ - 1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* PluginRegistry.m */; }; + 2D92224B1EC342E7007564B0 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 7484D44614CC7A0233629D78 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */; }; 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; @@ -21,7 +22,6 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - B1F3D14E8117A6C9F65810E0 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D558BB7489B1C82B42A9097 /* libPods-Runner.a */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -40,11 +40,10 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1498D2321E8E86230040F4C2 /* PluginRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PluginRegistry.h; sourceTree = ""; }; - 1498D2331E8E89220040F4C2 /* PluginRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PluginRegistry.m; sourceTree = ""; }; + 2D9222491EC342E7007564B0 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; - 4D558BB7489B1C82B42A9097 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -58,6 +57,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -67,7 +67,7 @@ files = ( 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, - B1F3D14E8117A6C9F65810E0 /* libPods-Runner.a in Frameworks */, + 7484D44614CC7A0233629D78 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -117,6 +117,8 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 2D9222491EC342E7007564B0 /* GeneratedPluginRegistrant.h */, + 2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */, 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 97C146FA1CF9000F007C117D /* Main.storyboard */, @@ -124,8 +126,6 @@ 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 97C147021CF9000F007C117D /* Info.plist */, 97C146F11CF9000F007C117D /* Supporting Files */, - 1498D2321E8E86230040F4C2 /* PluginRegistry.h */, - 1498D2331E8E89220040F4C2 /* PluginRegistry.m */, ); path = Runner; sourceTree = ""; @@ -141,7 +141,7 @@ CF3B75C9A7D2FA2A4C99F110 /* Frameworks */ = { isa = PBXGroup; children = ( - 4D558BB7489B1C82B42A9097 /* libPods-Runner.a */, + ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */, ); name = Frameworks; sourceTree = ""; @@ -292,7 +292,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -304,7 +304,7 @@ files = ( 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 97C146F31CF9000F007C117D /* main.m in Sources */, - 1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */, + 2D92224B1EC342E7007564B0 /* GeneratedPluginRegistrant.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/packages/shared-preferences/example/ios/Runner/AppDelegate.m b/packages/shared-preferences/example/ios/Runner/AppDelegate.m index 3b6ab51b9e11..8882024dbad4 100644 --- a/packages/shared-preferences/example/ios/Runner/AppDelegate.m +++ b/packages/shared-preferences/example/ios/Runner/AppDelegate.m @@ -1,38 +1,15 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #include "AppDelegate.h" -#include "PluginRegistry.h" +#include "GeneratedPluginRegistrant.h" -@implementation AppDelegate { - PluginRegistry *plugins; -} +@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - FlutterViewController *flutterController = - (FlutterViewController *)self.window.rootViewController; - plugins = [[PluginRegistry alloc] initWithController:flutterController]; - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + [GeneratedPluginRegistrant registerWithRegistry:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.h b/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.h new file mode 100644 index 000000000000..474638bbc514 --- /dev/null +++ b/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.h @@ -0,0 +1,16 @@ +// +// Generated file. Do not edit. +// + +#ifndef GeneratedPluginRegistrant_h +#define GeneratedPluginRegistrant_h + +#import + +#import "SharedPreferencesPlugin.h" + +@interface GeneratedPluginRegistrant : NSObject ++ (void)registerWithRegistry:(NSObject*)registry; +@end + +#endif /* GeneratedPluginRegistrant_h */ diff --git a/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.m b/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.m new file mode 100644 index 000000000000..791be9acff73 --- /dev/null +++ b/packages/shared-preferences/example/ios/Runner/GeneratedPluginRegistrant.m @@ -0,0 +1,13 @@ +// +// Generated file. Do not edit. +// + +#import "GeneratedPluginRegistrant.h" + +@implementation GeneratedPluginRegistrant + ++ (void)registerWithRegistry:(NSObject*)registry { + [SharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"SharedPreferencesPlugin"]]; +} + +@end diff --git a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.h b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.h index 179d28c88fd3..88962427e1ab 100644 --- a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.h +++ b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.h @@ -1,5 +1,4 @@ #import -@interface SharedPreferencesPlugin : NSObject -- initWithController:(FlutterViewController *)controller; +@interface SharedPreferencesPlugin : NSObject @end diff --git a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m index 5d148f7ab709..7c8c7ee2531a 100644 --- a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m +++ b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m @@ -6,16 +6,12 @@ static NSString *const CHANNEL_NAME = @"plugins.flutter.io/shared_preferences"; -@implementation SharedPreferencesPlugin { - FlutterMethodChannel *_channel; -} - -- (instancetype)initWithController:(FlutterViewController *)controller { - if (self = [super init]) { - _channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME - binaryMessenger:controller]; +@implementation SharedPreferencesPlugin - [_channel setMethodCallHandler:^(FlutterMethodCall *call, ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME + binaryMessenger:registrar.messenger]; + [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { NSString *method = [call method]; NSDictionary *arguments = [call arguments]; @@ -64,13 +60,6 @@ - (instancetype)initWithController:(FlutterViewController *)controller { result(FlutterMethodNotImplemented); } }]; - } - return self; -} - -- (void)dealloc { - [_channel setMethodCallHandler:nil]; - _channel = nil; } #pragma mark - Private diff --git a/packages/shared-preferences/pubspec.yaml b/packages/shared-preferences/pubspec.yaml index a7d42a340e44..58556d93ac04 100644 --- a/packages/shared-preferences/pubspec.yaml +++ b/packages/shared-preferences/pubspec.yaml @@ -1,6 +1,6 @@ name: shared_preferences -version: 0.1.1 +version: 0.2.0 description: A Flutter plugin for reading and writing simple key-value pairs author: Flutter Team homepage: https://github.com/flutter/plugins