Skip to content

Commit

Permalink
Updated to new expo unimodules setup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbbb committed Dec 8, 2021
1 parent b59167d commit 8d7c186
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 113 deletions.
19 changes: 10 additions & 9 deletions ios/EXSMS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ Pod::Spec.new do |s|
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']
s.platform = :ios, '10.0'
s.platform = :ios, '12.0'
s.source = { git: 'https://github.com/expo/expo.git' }
s.source_files = 'EXSMS/**/*.{h,m}'
s.preserve_paths = 'EXSMS/**/*.{h,m}'
s.requires_arc = true

s.dependency 'UMCore'
s.dependency 'UMPermissionsInterface'

end
s.static_framework = true

s.dependency 'ExpoModulesCore'

if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
s.source_files = "#{s.name}/**/*.h"
s.vendored_frameworks = "#{s.name}.xcframework"
else
s.source_files = "#{s.name}/**/*.{h,m}"
end
end
8 changes: 4 additions & 4 deletions ios/EXSMS/EXSMSModule.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2018 650 Industries. All rights reserved.

#import <UMCore/UMExportedModule.h>
#import <UMCore/UMModuleRegistryConsumer.h>
#import <ExpoModulesCore/EXExportedModule.h>
#import <ExpoModulesCore/EXModuleRegistryConsumer.h>

@interface EXSMSModule : UMExportedModule <UMModuleRegistryConsumer>
@end
@interface EXSMSModule : EXExportedModule <EXModuleRegistryConsumer>
@end
81 changes: 42 additions & 39 deletions ios/EXSMS/EXSMSModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
#import <MessageUI/MessageUI.h>
#import <Messages/Messages.h>
#import <EXSMS/EXSMSModule.h>
#import <UMCore/UMUtilities.h>
#import <UMPermissionsInterface/UMPermissionsInterface.h>
#if SD_MAC
#import <CoreServices/CoreServices.h>
#else
#import <MobileCoreServices/MobileCoreServices.h>
@interface EXSMSModule () <MFMessageComposeViewControllerDelegate>
@property (nonatomic, weak) id<UMPermissionsInterface> permissionsManager;
@property (nonatomic, weak) id<UMUtilitiesInterface> utils;
@property (nonatomic, strong) UMPromiseResolveBlock resolve;
@property (nonatomic, strong) UMPromiseRejectBlock reject;

@property (nonatomic, weak) id<EXUtilitiesInterface> utils;
@property (nonatomic, strong) EXPromiseResolveBlock resolve;
@property (nonatomic, strong) EXPromiseRejectBlock reject;


@end

@implementation EXSMSModule
UM_EXPORT_MODULE(ExpoSMS);

EX_EXPORT_MODULE(ExpoSMS);

- (dispatch_queue_t)methodQueue
{
Expand All @@ -20,28 +26,26 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

- (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
- (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
{
_permissionsManager = [moduleRegistry getModuleImplementingProtocol:@protocol(UMPermissionsInterface)];
_utils = [moduleRegistry getModuleImplementingProtocol:@protocol(UMUtilitiesInterface)];
_utils = [moduleRegistry getModuleImplementingProtocol:@protocol(EXUtilitiesInterface)];
}


UM_EXPORT_METHOD_AS(isAvailableAsync,
isAvailable:(UMPromiseResolveBlock)resolve
rejecter:(UMPromiseRejectBlock)reject)
EX_EXPORT_METHOD_AS(isAvailableAsync,
isAvailable:(EXPromiseResolveBlock)resolve
rejecter:(EXPromiseRejectBlock)reject)
{
dispatch_async(dispatch_get_main_queue(), ^{
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sms:"]];
resolve(@(canOpenURL));
});
resolve(@([MFMessageComposeViewController canSendText]));
}
UM_EXPORT_METHOD_AS(sendSMSAsync,

EX_EXPORT_METHOD_AS(sendSMSAsync,
sendSMS:(NSArray<NSString *> *)addresses
message:(NSString *)message
resolver:(UMPromiseResolveBlock)resolve
rejecter:(UMPromiseRejectBlock)reject)
resolver:(EXPromiseResolveBlock)resolve
rejecter:(EXPromiseRejectBlock)reject)
{

if (![MFMessageComposeViewController canSendText]) {
reject(@"E_SMS_UNAVAILABLE", @"SMS service not available", nil);
return;
Expand All @@ -50,24 +54,25 @@ - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
reject(@"E_SMS_SENDING_IN_PROGRESS", @"Different SMS sending in progress. Await the old request and then try again.", nil);
return;
}

_resolve = resolve;
_reject = reject;

MFMessageComposeViewController *messageComposeViewController = [[MFMessageComposeViewController alloc] init];
messageComposeViewController.messageComposeDelegate = self;
// messageComposeViewController.recipients = addresses;
messageComposeViewController.body = message;
UM_WEAKIFY(self);
[UMUtilities performSynchronouslyOnMainThread:^{
UM_ENSURE_STRONGIFY(self);
[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];
}];

[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];

}
UM_EXPORT_METHOD_AS(sendSMSWithiMessageAsync,

EX_EXPORT_METHOD_AS(sendSMSWithiMessageAsync,
sendSMS:(NSArray<NSString *> *)addresses
message:(NSString *)message
imessageAttachment:(NSDictionary *)imessageAttachment
resolver:(UMPromiseResolveBlock)resolve
rejecter:(UMPromiseRejectBlock)reject)
resolver:(EXPromiseResolveBlock)resolve
rejecter:(EXPromiseRejectBlock)reject)
{
if (![MFMessageComposeViewController canSendText]) {
reject(@"E_SMS_UNAVAILABLE", @"SMS service not available", nil);
Expand Down Expand Up @@ -118,10 +123,7 @@ - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
[iMessageLayout setTrailingSubcaption: layoutParams[key]];
}
}
// NSString *stringURL = [NSString stringWithFormat:@"%@%@",NSTemporaryDirectory(),@"temp.jpg"];
// NSURL *urlImage = [[NSURL alloc]initFileURLWithPath:stringURL];
// NSData *dataImage = UIImageJPEGRepresentation([self imageWithView:self.myViewBgImageConLogoDaSalvare], 0.0);
// [dataImage writeToURL:urlImage atomically:true];

// Add layout and url params to main imessage
iMessage.URL = urlComponents.URL;

Expand All @@ -141,18 +143,18 @@ - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
messageComposeViewController.body = message;
messageComposeViewController.message = iMessage;

UM_WEAKIFY(self);
[UMUtilities performSynchronouslyOnMainThread:^{
UM_ENSURE_STRONGIFY(self);
[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];
}];
[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];

}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
{

NSDictionary *resolveData;

NSString *rejectMessage;

switch (result) {
case MessageComposeResultCancelled:
resolveData = @{@"result": @"cancelled"};
Expand All @@ -167,9 +169,10 @@ - (void)messageComposeViewController:(MFMessageComposeViewController *)controlle
rejectMessage = @"SMS message sending failed with unknown error";
break;
}
UM_WEAKIFY(self);

EX_WEAKIFY(self);
[controller dismissViewControllerAnimated:YES completion:^{
UM_ENSURE_STRONGIFY(self);
EX_ENSURE_STRONGIFY(self);
if (rejectMessage) {
self->_reject(@"E_SMS_SENDING_FAILED", rejectMessage, nil);
} else {
Expand Down
82 changes: 30 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,43 @@
{
"_args": [
[
"[email protected]",
"/Users/kanethomas/fadmania"
]
],
"_from": "[email protected]",
"_id": "[email protected]",
"_inBundle": false,
"_integrity": "sha512-rGZkTsCLqbigUD7OKYHEt9vYBMG43ne+j8NvWbBwl1DFtkPcAZQIBN7pMFnXjRY0FLZnFePFDeYpboGquyQrgQ==",
"_location": "/expo-sms",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "[email protected]",
"name": "expo-sms",
"escapedName": "expo-sms",
"rawSpec": "5.0.1",
"saveSpec": null,
"fetchSpec": "5.0.1"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/expo-sms/-/expo-sms-5.0.1.tgz",
"_spec": "5.0.1",
"_where": "/Users/kanethomas/fadmania",
"author": {
"name": "650 Industries, Inc."
},
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"name": "expo-sms",
"version": "10.1.0",
"description": "Provides access to the system's UI/app for sending SMS messages.",
"devDependencies": {
"expo-module-scripts": "^1.0.0"
},
"gitHead": "f213c9be2a909dae42a0a27d8aa4b9eac8e97be1",
"homepage": "https://docs.expo.io/versions/latest/sdk/sms/",
"jest": {
"preset": "expo-module-scripts"
"main": "build/SMS.js",
"types": "build/SMS.d.ts",
"sideEffects": false,
"scripts": {
"build": "expo-module build",
"clean": "expo-module clean",
"lint": "expo-module lint",
"test": "expo-module test",
"prepare": "expo-module prepare",
"prepublishOnly": "expo-module prepublishOnly",
"expo-module": "expo-module"
},
"keywords": [
"react-native",
"expo",
"sms"
],
"license": "MIT",
"main": "build/SMS.js",
"name": "expo-sms",
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo.git"
"url": "https://github.com/expo/expo.git",
"directory": "packages/expo-sms"
},
"scripts": {},
"sideEffects": false,
"types": "build/SMS.d.ts",
"unimodulePeerDependencies": {
"@unimodules/core": "*",
"unimodules-permissions-interface": "*"
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"author": "650 Industries, Inc.",
"license": "MIT",
"homepage": "https://docs.expo.dev/versions/latest/sdk/sms/",
"jest": {
"preset": "expo-module-scripts"
},
"dependencies": {},
"devDependencies": {
"expo-module-scripts": "^2.0.0"
},
"version": "5.0.1"
"peerDependencies": {
"expo": "*"
}
}
2 changes: 1 addition & 1 deletion src/ExpoSMS.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { NativeModulesProxy } from '@unimodules/core';
import { NativeModulesProxy } from "expo-modules-core";
export default NativeModulesProxy.ExpoSMS;
20 changes: 12 additions & 8 deletions src/SMS.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Platform } from '@unimodules/core';
import ExpoSMS from './ExpoSMS';
import { UnavailabilityError, Platform } from "expo-modules-core";
import ExpoSMS from "./ExpoSMS";

type SMSResponse = {
result: 'unknown' | 'sent' | 'cancelled';
result: "unknown" | "sent" | "cancelled";
};

type MSMessageLayout = {
Expand All @@ -13,7 +13,7 @@ type MSMessageLayout = {
subcaption?: string;
trailingCaption?: string;
trailingSubcaption?: string;
}
};

type URLQueryItems = any;

Expand All @@ -26,15 +26,15 @@ type URLQueryItems = any;
type MSMessageInfo = {
urlQueryItems: any;
layoutParams: MSMessageLayout;
}
};

export async function sendSMSAsync(
addresses: string | string[],
message: string
): Promise<SMSResponse> {
const finalAddresses = Array.isArray(addresses) ? addresses : [addresses];
if (!ExpoSMS.sendSMSAsync) {
throw new Error(`SMS.sendSMSAsync is not supported on ${Platform.OS}`);
throw new UnavailabilityError("expo-sms", "sendSMSAsync");
}
return ExpoSMS.sendSMSAsync(finalAddresses, message);
}
Expand All @@ -46,9 +46,13 @@ export async function sendSMSWithiMessageAsync(
): Promise<SMSResponse> {
const finalAddresses = Array.isArray(addresses) ? addresses : [addresses];
if (!ExpoSMS.sendSMSAsync) {
throw new Error(`SMS.sendSMSAsync is not supported on ${Platform.OS}`);
throw new UnavailabilityError("expo-sms", "sendSMSAsync");
}
return ExpoSMS.sendSMSWithiMessageAsync(finalAddresses, message, imessageInfo);
return ExpoSMS.sendSMSWithiMessageAsync(
finalAddresses,
message,
imessageInfo
);
}

export async function isAvailableAsync(): Promise<boolean> {
Expand Down
32 changes: 32 additions & 0 deletions src/SMS.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @needsAudit
export type SMSResponse = {
/**
* Status of SMS action invoked by the user.
*/
result: "unknown" | "sent" | "cancelled";
};

// @needsAudit
/**
* An object that is used to describe an attachment that is included with a SMS message.
*/
export type SMSAttachment = {
/**
* The content URI of the attachment. The URI needs be a content URI so that it can be accessed by
* other applications outside of Expo. (See [FileSystem.getContentUriAsync](../filesystem/#filesystemgetcontenturiasyncfileuri))
*/
uri: string;
/**
* The mime type of the attachment such as `image/png`.
*/
mimeType: string;
/**
* The filename of the attachment.
*/
filename: string;
};

// @needsAudit @docsMissing
export type SMSOptions = {
attachments?: SMSAttachment | SMSAttachment[] | undefined;
};

0 comments on commit 8d7c186

Please sign in to comment.