Skip to content

Commit fc7bb30

Browse files
committed
chore(ios): use swift in ios
1 parent 51e5e40 commit fc7bb30

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed

MusicLibrary.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313
s.platforms = { :ios => min_ios_version_supported }
1414
s.source = { :git => "https://github.com/nodefinity/react-native-music-library.git", :tag => "#{s.version}" }
1515

16-
s.source_files = "ios/**/*.{h,m,mm,cpp}"
16+
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
1717
s.private_header_files = "ios/**/*.h"
1818

1919
install_modules_dependencies(s)

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ SPEC CHECKSUMS:
21792179
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
21802180
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
21812181
hermes-engine: 314be5250afa5692b57b4dd1705959e1973a8ebe
2182-
MusicLibrary: c85226f5ab7032af7a2af2a6b640da602b4b8b58
2182+
MusicLibrary: 8006e08ff31df196b24c363f9f3e83044dad9792
21832183
RCT-Folly: e78785aa9ba2ed998ea4151e314036f6c49e6d82
21842184
RCTDeprecation: 83ffb90c23ee5cea353bd32008a7bca100908f8c
21852185
RCTRequired: eb7c0aba998009f47a540bec9e9d69a54f68136e

ios/MusicLibrary.mm

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#import "MusicLibrary.h"
2+
#import "MusicLibrary-Swift.h"
23

3-
@implementation MusicLibrary
4-
RCT_EXPORT_MODULE()
5-
6-
- (NSNumber *)multiply:(double)a b:(double)b {
7-
NSNumber *result = @(a * b);
4+
@implementation MusicLibrary {
5+
MusicLibraryImpl *musicLibrary;
6+
}
87

9-
return result;
8+
- (instancetype) init {
9+
if (self = [super init]) {
10+
musicLibrary = [MusicLibraryImpl new];
11+
}
12+
return self;
1013
}
1114

1215
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
@@ -15,4 +18,47 @@ - (NSNumber *)multiply:(double)a b:(double)b {
1518
return std::make_shared<facebook::react::NativeMusicLibrarySpecJSI>(params);
1619
}
1720

21+
- (void)getTracksAsync:(JS::NativeMusicLibrary::InternalTrackOptions &)options resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
22+
NSDictionary *optionsDict = @{}; // Convert JS options to NSDictionary
23+
NSDictionary *result = [musicLibrary getTracksAsync:optionsDict];
24+
resolve(result);
25+
}
26+
27+
- (void)getTrackMetadataAsync:(nonnull NSString *)trackId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
28+
NSDictionary *result = [musicLibrary getTrackMetadataAsync:trackId];
29+
resolve(result);
30+
}
31+
32+
- (void)getTracksByAlbumAsync:(nonnull NSString *)albumId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
33+
NSArray *result = [musicLibrary getTracksByAlbumAsync:albumId];
34+
resolve(result);
35+
}
36+
37+
- (void)getTracksByArtistAsync:(nonnull NSString *)artistId options:(JS::NativeMusicLibrary::InternalTrackOptions &)options resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
38+
NSDictionary *optionsDict = @{}; // Convert JS options to NSDictionary
39+
NSDictionary *result = [musicLibrary getTracksByArtistAsync:artistId options:optionsDict];
40+
resolve(result);
41+
}
42+
43+
- (void)getAlbumsAsync:(JS::NativeMusicLibrary::InternalAlbumOptions &)options resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
44+
NSDictionary *optionsDict = @{}; // Convert JS options to NSDictionary
45+
NSDictionary *result = [musicLibrary getAlbumsAsync:optionsDict];
46+
resolve(result);
47+
}
48+
49+
- (void)getAlbumsByArtistAsync:(nonnull NSString *)artistId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
50+
NSArray *result = [musicLibrary getAlbumsByArtistAsync:artistId];
51+
resolve(result);
52+
}
53+
54+
- (void)getArtistsAsync:(JS::NativeMusicLibrary::InternalArtistOptions &)options resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
55+
NSDictionary *optionsDict = @{}; // Convert JS options to NSDictionary
56+
NSDictionary *result = [musicLibrary getArtistsAsync:optionsDict];
57+
resolve(result);
58+
}
59+
60+
+ (NSString *)moduleName {
61+
return @"MusicLibraryImpl";
62+
}
63+
1864
@end

ios/MusicLibraryImpl.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// MusicLibraryImpl.swift
3+
// MusicLibrary
4+
//
5+
//
6+
7+
import Foundation
8+
9+
@objc public class MusicLibraryImpl: NSObject {
10+
11+
@objc public func getTracksAsync(_ options: [String: Any]) -> [String: Any] {
12+
return [
13+
"items": [],
14+
"hasNextPage": false,
15+
"endCursor": NSNull(),
16+
"totalCount": 0,
17+
]
18+
}
19+
20+
@objc public func getTrackMetadataAsync(_ trackId: String) -> [String: Any] {
21+
return [:]
22+
}
23+
24+
@objc public func getTracksByAlbumAsync(_ albumId: String) -> [[String: Any]] {
25+
return []
26+
}
27+
28+
@objc public func getTracksByArtistAsync(_ artistId: String, options: [String: Any]) -> [String: Any] {
29+
return [:]
30+
}
31+
32+
@objc public func getAlbumsAsync(_ options: [String: Any]) -> [String: Any] {
33+
return [:]
34+
}
35+
36+
@objc public func getAlbumsByArtistAsync(_ artistId: String) -> [[String: Any]] {
37+
return []
38+
}
39+
40+
@objc public func getArtistsAsync(_ options: [String: Any]) -> [String: Any] {
41+
return [:]
42+
}
43+
}

0 commit comments

Comments
 (0)