Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call ensureInitialized before executing onBootComplete handle #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ build/
.idea/

*.lock
example/ios/
example/ios/
example/.flutter-plugins-dependencies
37 changes: 37 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.idea/
.vagrant/
.sconsign.dblite
.svn/

.DS_Store
*.swp
profile

DerivedData/
build/
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m

.generated/

*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3

!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3

xcuserdata

*.moved-aside

*.pyc
*sync/
Icon?
.tags*

/Flutter/Generated.xcconfig
/Flutter/flutter_export_environment.sh
Empty file added ios/Assets/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions ios/Classes/BootCompletedPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <Flutter/Flutter.h>

@interface BootCompletedPlugin : NSObject<FlutterPlugin>
@end
15 changes: 15 additions & 0 deletions ios/Classes/BootCompletedPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import "BootCompletedPlugin.h"
#if __has_include(<boot_completed/boot_completed-Swift.h>)
#import <boot_completed/boot_completed-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "boot_completed-Swift.h"
#endif

@implementation BootCompletedPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftBootCompletedPlugin registerWithRegistrar:registrar];
}
@end
14 changes: 14 additions & 0 deletions ios/Classes/SwiftBootCompletedPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Flutter
import UIKit

public class SwiftBootCompletedPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "boot_completed", binaryMessenger: registrar.messenger())
let instance = SwiftBootCompletedPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
result("iOS " + UIDevice.current.systemVersion)
}
}
23 changes: 23 additions & 0 deletions ios/boot_completed.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint boot_completed.podspec' to validate before publishing.
#
Pod::Spec.new do |s|
s.name = 'boot_completed'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.description = <<-DESC
A new flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '8.0'

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.swift_version = '5.0'
end
4 changes: 4 additions & 0 deletions lib/boot_completed.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'package:path_provider/path_provider.dart' as path_provider;
import 'dart:io';
Expand Down Expand Up @@ -32,6 +33,9 @@ Future<void> setBootCompletedFunction(Function functionToExecute) async {

//this function is called by the android side
Future<void> _executeOnBootCompleted() async {
// Ensure the application is initialized
WidgetsFlutterBinding.ensureInitialized();

//this handle should have been set by the application that's using this plugin
//by calling setBootCompletedFunction
final userBootCompletedHandle = await _getUserBootCompletedHandle();
Expand Down