Skip to content

Commit

Permalink
update to remove Swift from the iOS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiralArm Consulting Ltd committed Feb 3, 2019
1 parent 5a80fce commit 8c33827
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 124 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0

* Removed Swift code. Now uses Objective C for iOS implementation

## 0.0.1

* Initial release.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ this should return a list of the preferred/current language locales setup on the


## iOS
This is a Swift plug-in and seems to suffer from the issues mentioned [here](https://github.com/flutter/flutter/issues/16049).

But if you follow the advice in this [comment](https://github.com/flutter/flutter/issues/16049#issuecomment-438589363) , but set the Swift Version to 4.0 not 3.2. it should work fine.
When first created this was a Swift based plugin, but due to [these issues](https://github.com/flutter/flutter/issues/16049) the Swift code has been removed and it now uses a simple Objective C call.


## Getting Started
Expand Down
16 changes: 0 additions & 16 deletions example/README.md

This file was deleted.

17 changes: 17 additions & 0 deletions example/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
6 changes: 6 additions & 0 deletions example/android/app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 23 additions & 0 deletions example/android/app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
2 changes: 0 additions & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def parse_KV_file(file, separator='=')
end

target 'Runner' do
use_frameworks!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
Expand Down
102 changes: 46 additions & 56 deletions example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions example/ios/Runner/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : FlutterAppDelegate

@end
13 changes: 13 additions & 0 deletions example/ios/Runner/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end
13 changes: 0 additions & 13 deletions example/ios/Runner/AppDelegate.swift

This file was deleted.

1 change: 0 additions & 1 deletion example/ios/Runner/Runner-Bridging-Header.h

This file was deleted.

9 changes: 9 additions & 0 deletions example/ios/Runner/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:devicelocale/devicelocale.dart';

void main() => runApp(MyApp());

/// Demo getting a device locale
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
Expand Down
15 changes: 13 additions & 2 deletions ios/Classes/DevicelocalePlugin.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#import "DevicelocalePlugin.h"
#import <devicelocale/devicelocale-Swift.h>

@implementation DevicelocalePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftDevicelocalePlugin registerWithRegistrar:registrar];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"uk.spiralarm.flutter/devicelocale"
binaryMessenger:[registrar messenger]];
DevicelocalePlugin* instance = [[DevicelocalePlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"preferredLanguages" isEqualToString:call.method]) {
result([NSLocale preferredLanguages]);
} else {
result(FlutterMethodNotImplemented);
}
}
@end
24 changes: 0 additions & 24 deletions ios/Classes/SwiftDevicelocalePlugin.swift

This file was deleted.

15 changes: 9 additions & 6 deletions lib/devicelocale.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/// Copyright (c) 2019, Steve Rogers. All rights reserved. Use of this source code
/// is governed by an Apache License 2.0 that can be found in the LICENSE file.
import 'dart:async';

// Copyright (c) 2019, Steve Rogers. All rights reserved. Use of this source code
// is governed by an Apache License 2.0 that can be found in the LICENSE file.
import 'package:flutter/services.dart';

/// A Simple plug-in that can be used to interogate a device( iOS or Android) to obtain a list of current set up locales
/// the currently used locale should be the first in the list
///
/// The currentl default locale should be the first in the list
class Devicelocale {
static const MethodChannel _channel = const MethodChannel('uk.spiralarm.flutter/devicelocale');
static const MethodChannel _channel =
const MethodChannel('uk.spiralarm.flutter/devicelocale');

/// Get a String List of locales from the device
/// Returns a 'List' of locales from the device
///
/// for example **['en-GB', 'es-GB']**
static Future<List> get preferredLanguages async {
final List version = await _channel.invokeMethod('preferredLanguages');
return version;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devicelocale
description: A Flutter package that can be used to extract the locales that are currently defined on a device with the current locale set as the first in the list.
version: 0.0.1
version: 0.1.0
author: Steve Rogers <[email protected]>
homepage: https://github.com/magnatronus/flutter-devicelocale

Expand Down

0 comments on commit 8c33827

Please sign in to comment.