Skip to content

Commit

Permalink
iOS compilation failure issue UWICompSociety#31 - plugin changed
Browse files Browse the repository at this point in the history
  • Loading branch information
richtwin567 committed Sep 11, 2020
1 parent cbf822f commit 92d30df
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 65 deletions.
17 changes: 16 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
compileSdkVersion 28

Expand All @@ -40,11 +46,20 @@ android {
versionName flutterVersionName
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
buildToolsVersion '30.0.2'
Expand Down
22 changes: 6 additions & 16 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,23 @@
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

<!--
io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here.
-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
-->

<application
android:name="io.flutter.app.FlutterApplication"
android:icon="@mipmap/ic_launcher"
android:label="fst_app_flutter">

<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->

android:label="FSTGo">

<activity
android:name=".MainActivity"
Expand Down
10 changes: 5 additions & 5 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
import ContactsUI
import GoogleMaps

/* public class NativeContact: NSObject, CNContactViewControllerDelegate{
public class NativeContact: NSObject, CNContactViewControllerDelegate{

private(set) var displayName: String
private(set) var note: String
Expand Down Expand Up @@ -102,7 +102,7 @@ import GoogleMaps
/**
* Creates an instance of NativeContactPhone.
*
* @param map A map object passed from the NativeContact constructor from the invoke
* map A map object passed from the NativeContact constructor from the invoke
* method call arguments passed in dart saveNatively method in
* contact_model.dart.
*/
Expand All @@ -119,7 +119,7 @@ import GoogleMaps
}

}
*/


@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
Expand All @@ -130,7 +130,7 @@ import GoogleMaps
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let contactsChannel = FlutterMethodChannel(name: "com.example.fst_app_flutter/native",
binaryMessenger: controller.binaryMessenger)
/* contactsChannel.setMethodCallHandler({
contactsChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: FlutterResult) -> Void in
// Note: this method is invoked on the UI thread.
guard call.method == "saveNatively" else {
Expand All @@ -141,7 +141,7 @@ import GoogleMaps
var contact = NativeContact(map:args)
contact.saveNatively()
}
}) */
})
GMSServices.provideAPIKey("AIzaSyC8crEFAO6MSNJMRK1lmo-WnSL7RLFu87w")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
Expand Down
5 changes: 3 additions & 2 deletions lib/models/sharing/vcard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import 'package:fst_app_flutter/models/from_postgres/contact/contact_type.dart';
// TODO: document @richtwin567
class VCard {
final String vcf;
final String name;

VCard(this.vcf);
VCard(this.vcf, this.name);

factory VCard.fromContact(Contact contact) {
String rawPhoneNumber(String phone) {
Expand Down Expand Up @@ -60,6 +61,6 @@ class VCard {
}
vCard += 'END:VCARD';

return VCard(vCard);
return VCard(vCard, contact.name);
}
}
7 changes: 3 additions & 4 deletions lib/utils/open_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import 'package:url_launcher/url_launcher.dart' as urlLauncher;
///
openUrl(String url) async {
if (await urlLauncher.canLaunch(url)) {
await urlLauncher.launch(url);
} else {
//TODO: not entirely sure what I want to happen here
throw 'Can\'t open $url';
try {
await urlLauncher.launch(url);
} catch (e) {}
}
}
43 changes: 24 additions & 19 deletions lib/utils/social_media_contact_share.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_share/flutter_share.dart';
import 'package:fst_app_flutter/utils/open_url.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share/share.dart';
import 'package:fst_app_flutter/models/sharing/vcard.dart';
import 'package:fst_app_flutter/utils/permissions.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';

// TODO: document @richtwin567
Expand All @@ -17,26 +19,29 @@ openWhatsAppChat({@required String phone, String message = ''}) async {
}
}

if (await canLaunch(formatUrl())) {
try {
await launch((formatUrl()));
} catch (e) {}
}
await openUrl(formatUrl());
}

shareContactToWhatsApp(VCard vCard) async {
try {
if (await requestPermission(Permission.storage)) {
String filepath = '${Directory.systemTemp.parent.path}/cache/temp.vcf';
File vcf = File(filepath)..createSync();
vcf.writeAsStringSync(vCard.vcf);
await FlutterShare.shareFile(
title: 'Share contact',
text: 'Share contact',
chooserTitle: 'Share contact with',
filePath: filepath,
);
final RegExp filenameCheck = RegExp(r'^([><":?\/\\*|,;\[\]]*)$');
var filename = (vCard.name.toLowerCase().split(' ')
..removeWhere((e) => e == '-' || e == '_'))
.reduce((value, element) => value + '-' + element)
.toString();
if (!filenameCheck.hasMatch(filename)) {
if (await requestPermission(Permission.storage)) {
String filepath =
join((await getTemporaryDirectory()).path, '$filename.vcf');
File vcf = File(filepath)..createSync();
vcf.writeAsStringSync(vCard.vcf);
await Share.shareFiles(
[filepath],
mimeTypes: ['text/directory'],
subject: vCard.name + "'s contact",
text: vCard.name
);
}
}
} catch (e) {
}
} catch (e) {}
}
Loading

0 comments on commit 92d30df

Please sign in to comment.