Skip to content

Commit

Permalink
Switch to ObjC++ (#849)
Browse files Browse the repository at this point in the history
* Switch to ObjC++

* Don't include .m files in sources

* Embed frameworks per permission
  • Loading branch information
zoontek authored Feb 24, 2024
1 parent bcb4c98 commit c5df1fe
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 38 deletions.
2 changes: 1 addition & 1 deletion RNPermissions.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.source = { :git => package["repository"]["url"], :tag => s.version }
s.source_files = "ios/*.{h,m,mm}"
s.source_files = "ios/*.{h,mm}"

if ENV['RCT_NEW_ARCH_ENABLED'] == "1" then
install_modules_dependencies(s)
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: ed48e5faac6751e66ee1261c4bd01643b436f112
React-utils: 6e5ad394416482ae21831050928ae27348f83487
ReactCommon: 840a955d37b7f3358554d819446bffcf624b2522
RNPermissions: 17daec882a3e12cc1d98baa7bbb7108a3515827e
RNPermissions: 09766cc679a5bb91aa300d7cbce64db250e1a5c3
RNVectorIcons: 210f910e834e3485af40693ad4615c1ec22fc02b
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312
Expand Down
4 changes: 0 additions & 4 deletions example/ios/RNPermissionsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
DDCFC0EE2B1CDF540082F946 /* PhotosUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDCFC0ED2B1CDF540082F946 /* PhotosUI.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,7 +25,6 @@
5709B34CF0A7D63546082F79 /* Pods-RNPermissionsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNPermissionsExample.release.xcconfig"; path = "Target Support Files/Pods-RNPermissionsExample/Pods-RNPermissionsExample.release.xcconfig"; sourceTree = "<group>"; };
5DCACB8F33CDC322A6C60F78 /* libPods-RNPermissionsExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNPermissionsExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RNPermissionsExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
DDCFC0ED2B1CDF540082F946 /* PhotosUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PhotosUI.framework; path = System/Library/Frameworks/PhotosUI.framework; sourceTree = SDKROOT; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand All @@ -36,7 +34,6 @@
buildActionMask = 2147483647;
files = (
0C80B921A6F3F58F76C31292 /* libPods-RNPermissionsExample.a in Frameworks */,
DDCFC0EE2B1CDF540082F946 /* PhotosUI.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -59,7 +56,6 @@
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
DDCFC0ED2B1CDF540082F946 /* PhotosUI.framework */,
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
5DCACB8F33CDC322A6C60F78 /* libPods-RNPermissionsExample.a */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "RNPermissionHandlerAppTrackingTransparency.h"

@import AppTrackingTransparency;
@import AdSupport;
#import <AdSupport/AdSupport.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>

@interface RNPermissionHandlerAppTrackingTransparency()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerBluetooth.h"

@import CoreBluetooth;
#import <CoreBluetooth/CoreBluetooth.h>

@interface RNPermissionHandlerBluetooth() <CBPeripheralManagerDelegate>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerCalendars.h"

@import EventKit;
#import <EventKit/EventKit.h>

@implementation RNPermissionHandlerCalendars

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerCalendarsWriteOnly.h"

@import EventKit;
#import <EventKit/EventKit.h>

@implementation RNPermissionHandlerCalendarsWriteOnly

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerCamera.h"

@import AVFoundation;
#import <AVFoundation/AVFoundation.h>

@implementation RNPermissionHandlerCamera

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerContacts.h"

@import Contacts;
#import <Contacts/Contacts.h>

@implementation RNPermissionHandlerContacts

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "RNPermissionHandlerFaceID.h"

@import LocalAuthentication;
@import UIKit;
#import <LocalAuthentication/LocalAuthentication.h>

static NSString* SETTING_KEY = @"@RNPermissions:Requested";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerLocationAccuracy.h"

@import CoreLocation;
#import <CoreLocation/CoreLocation.h>

@interface RNPermissionHandlerLocationAccuracy() <CLLocationManagerDelegate>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "RNPermissionHandlerLocationAlways.h"

@import CoreLocation;
@import UIKit;
#import <CoreLocation/CoreLocation.h>

@interface RNPermissionHandlerLocationAlways() <CLLocationManagerDelegate>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerLocationWhenInUse.h"

@import CoreLocation;
#import <CoreLocation/CoreLocation.h>

@interface RNPermissionHandlerLocationWhenInUse() <CLLocationManagerDelegate>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerMediaLibrary.h"

@import MediaPlayer;
#import <MediaPlayer/MediaPlayer.h>

@implementation RNPermissionHandlerMediaLibrary

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerMicrophone.h"

@import AVFoundation;
#import <AVFoundation/AVFoundation.h>

@implementation RNPermissionHandlerMicrophone

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerMotion.h"

@import CoreMotion;
#import <CoreMotion/CoreMotion.h>

@interface RNPermissionHandlerMotion()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "RNPermissionHandlerNotifications.h"

@import UserNotifications;
@import UIKit;
#import <UserNotifications/UserNotifications.h>

@interface RNPermissionHandlerNotifications()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "RNPermissionHandlerPhotoLibrary.h"
#import <React/RCTUtils.h>

@import Photos;
@import PhotosUI;
#import <Photos/Photos.h>
#import <PhotosUI/PhotosUI.h>

@implementation RNPermissionHandlerPhotoLibrary

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerPhotoLibraryAddOnly.h"

@import Photos;
#import <Photos/Photos.h>

@implementation RNPermissionHandlerPhotoLibraryAddOnly

Expand Down
2 changes: 1 addition & 1 deletion ios/RNPermissions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
};
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNPermissions" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerReminders.h"

@import EventKit;
#import <EventKit/EventKit.h>

@implementation RNPermissionHandlerReminders

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerSiri.h"

@import Intents;
#import <Intents/Intents.h>

@implementation RNPermissionHandlerSiri

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerSpeechRecognition.h"

@import Speech;
#import <Speech/Speech.h>

@implementation RNPermissionHandlerSpeechRecognition

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "RNPermissionHandlerStoreKit.h"

@import StoreKit;
#import <StoreKit/StoreKit.h>

@implementation RNPermissionHandlerStoreKit

Expand Down
48 changes: 42 additions & 6 deletions scripts/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ def setup_permissions(config)
return log_warning("Invalid config argument")
end

permissions_frameworks = {
'AppTrackingTransparency' => ['AdSupport', 'AppTrackingTransparency'],
'Bluetooth' => ['CoreBluetooth'],
'Calendars' => ['EventKit'],
'CalendarsWriteOnly' => ['EventKit'],
'Camera' => ['AVFoundation'],
'Contacts' => ['Contacts'],
'FaceID' => ['LocalAuthentication'],
'LocationAccuracy' => ['CoreLocation'],
'LocationAlways' => ['CoreLocation'],
'LocationWhenInUse' => ['CoreLocation'],
'MediaLibrary' => ['MediaPlayer'],
'Microphone' => ['AVFoundation'],
'Motion' => ['CoreMotion'],
'Notifications' => ['UserNotifications'],
'PhotoLibrary' => ['Photos', 'PhotosUI'],
'PhotoLibraryAddOnly' => ['Photos'],
'Reminders' => ['EventKit'],
'Siri' => ['Intents'],
'SpeechRecognition' => ['Speech'],
'StoreKit' => ['StoreKit']
}

module_dir = File.expand_path('..', __dir__)
ios_dir = File.join(module_dir, 'ios')
ios_dirents = Dir.entries(ios_dir).map { |entry| File.join(ios_dir, entry) }
Expand All @@ -18,20 +41,33 @@ def setup_permissions(config)
.map { |entry| File.basename(entry) }
.select { |name| config.include?(name) }

source_files = [
'"ios/*.{h,m,mm}"',
*directories.map { |name| "\"ios/#{name}/*.{h,m,mm}\"" }
]

unknown_permissions = config.reject { |name| directories.include?(name) }

unless unknown_permissions.empty?
log_warning("Unknown permissions: #{unknown_permissions.join(', ')}")
end

source_files = [
'"ios/*.{h,mm}"',
*directories.map { |name| "\"ios/#{name}/*.{h,mm}\"" }
].join(', ')

frameworks = directories
.reduce([]) do |acc, dir|
arr = permissions_frameworks[dir]
arr ? acc.concat(arr) : acc
end
.map { |name| "\"#{name}\"" }
.uniq
.join(', ')

podspec_path = File.join(module_dir, 'RNPermissions.podspec')
podspec = File.read(podspec_path)
podspec_content = podspec.gsub(/"ios\/\*\.{h,m,mm}".*/, source_files.join(', '))

podspec_content = podspec.gsub(
/"ios\/\*\.{h,mm}".*/,
source_files + "\n s.frameworks = #{frameworks}"
)

File.write(podspec_path, podspec_content)
end

0 comments on commit c5df1fe

Please sign in to comment.