Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing into Objective-C++ / React Native project #16

Open
dorkyboi opened this issue Oct 27, 2023 · 16 comments
Open

Importing into Objective-C++ / React Native project #16

dorkyboi opened this issue Oct 27, 2023 · 16 comments

Comments

@dorkyboi
Copy link

dorkyboi commented Oct 27, 2023

Hi, we are developing a React Native application which should integrate with TikTok. Because it is a React Native app, it is made in Objective-C and not Swift. It is also a quite old application with many changes to the codebase, so refactoring AppDelegate into Swift is not an option.

Disclosure: I know next to nothing when it comes to iOS development, so the more information – the better.

From what I understood, Swift code (when made right, e.g. with @objc) can be imported into Objective-C code directly using a -Swift postfix. However, when I do #import <TikTokOpenSDKCore/TikTokOpenSDKCore-Swift.h> the compiler says there's no such file. I have tried plenty of different variants in different files and languages, same using "" instead of <>, also tried including using SPM instead of CocoaPods, but all to no avail.

During my research, I have found out that importable headers are located in /Pods/Headers/Public. I've inspected TikTokOpenSDKCore folder and the only header present there is TikTokOpenSDKCore-umbrella.h. But this header appears to be next to useless when it comes to importing actual classes and everything else. All it seems to do is import UIKit.h and export a couple of variables. Still, I have tried importing it instead of -Swift.h, of course it didn't work.

One thought was that some of other libraries or project settings interfere, so I have tried installing TikTok SDK on a brand new React Native project – nothing has changed. So I doubt it has something to do with my project specifically.

At this point, I have spent an obscene number of hours trying to make this work, and I feel like my head is going to explode. Have to admit, I am desperate for any help, so please forgive me for tagging @stephen-boyle @nickdnk.

My podfile has:

target 'myproject' do
  pod 'TikTokOpenSDKCore' // installs v2.2.0
  pod 'TikTokOpenAuthSDK' // installs v2.2.0

My AppDelegate.mm:

// AppDelegate.mm
#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTLinkingManager.h>
#import <Firebase.h>
#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>
#import "RNBootSplash.h"
#import "RNSplashScreen.h"
#import <TikTokOpenSDKCore/TikTokOpenSDKCore-Swift.h> // <- file not found

@implementation AppDelegate

// ...

// Linking API
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  if ([TikTokURLHandler handleOpenURL:url]) { // <- Use of undeclared identifier 'TikTokURLHandler'
    return YES;
  }
  return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];

}

// ...

@end
@nickdnk
Copy link
Contributor

nickdnk commented Oct 27, 2023

#2 (comment) (don't use cocoapods)

@dorkyboi
Copy link
Author

Correct me if I'm wrong, but isn't @import unavailable when the project has .mm files (aka Objective-C++ Source)?

@nickdnk
Copy link
Contributor

nickdnk commented Oct 27, 2023

No idea. I just know that in a regular Objective-C project, the above syntax works fine if the package was added with SPM.

@dorkyboi
Copy link
Author

Well, yeah – after extensive research, it would seem that Swift can only be used in Objective-C++ files when importing with -Swift postfix. Refactoring AppDelegate.mm to Swift seems to be the only option left on the table, but I don't have nearly enough skills to effectively move all changes made to it by other libraries while making sure nothing breaks.

Guess we will have to use the old SDK, at least for iOS.

Any idea why importing doesn't work? Can it/will it be fixed in the future? Excluding the whole React Native community seems like a big deal.

@nickdnk
Copy link
Contributor

nickdnk commented Oct 28, 2023

I don't use React Native, but it seems this a known problem with RN and something they're debating how to fix: react-native-community/discussions-and-proposals#587

I don't work for TikTok, but I wouldn't expect this library to move away from SPM/Swift. I don't know if this particular problem is a limitation with RN or your ability to convert your AppDelegate to Swift. If it's the latter, I suggest you just get it done and move on.

@dorkyboi
Copy link
Author

Still, I find it quite weird that other imports (for example #import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>) do work but TikTok's SDK won't. Even though TikTok's documentation and this repo's readme both state that CocoaPods can be used as an alternative to SPM.

@dorkyboi dorkyboi changed the title Importing into Obj-C project Importing into Objective-C++ / React Native project Oct 28, 2023
@stephen-boyle
Copy link
Collaborator

@dorkyboi sorry for the trouble you are experiencing. I am looking into this issue and will get back to you.

@areejmayadeh
Copy link

@dorkyboi sorry for the trouble you are experiencing. I am looking into this issue and will get back to you.

Any update on this ?

@fobos531
Copy link

@dorkyboi sorry for the trouble you are experiencing. I am looking into this issue and will get back to you.

Any update on this ?

Same, I would love to use this within a React Native iOS app! @stephen-boyle

@viet795
Copy link

viet795 commented Jan 25, 2024

image

@Nishannb
Copy link

Nishannb commented Jul 7, 2024

Is there any updates on this? I am also looking forward for Tiktok Share Kit for React Native.

@a7510774
Copy link

@dorkyboi很抱歉给您带来麻烦。我正在调查此问题并会回复您。

有最新消息吗?

我使用Choose File > Add Package Dependencies成功了!

@Nishannb
Copy link

Nishannb commented Sep 1, 2024

@a7510774 you mean you added the dependencies, but were you able to implement share kit in your react app.

@a7510774
Copy link

a7510774 commented Sep 2, 2024

@a7510774 you mean you added the dependencies, but were you able to implement share kit in your react app.

可以的,我已成功导入我的OC项目

@Nishannb
Copy link

@a7510774 Can you help me? If there is something that I can reference, can you send it to me. Is your project is shareable for reference?

@a7510774
Copy link

@a7510774 Can you help me? If there is something that I can reference, can you send it to me. Is your project is shareable for reference?

我不太清楚RN项目是不是这样操作,我使用的是原生的OC语言,按官方的指引,使用swift包依赖是成功加入了项目中,具体操作如官方的指引:
Swift Package Manager

Add the library to your XCode project as a Swift Package:

Click File -> Add Packages...
Paste the repository URL: https://github.com/tiktok/tiktok-opensdk-ios
Select Dependency Rule -> Up to Next Major Version and input the major version you want (i.e. 2.3.0)
Select Add to Project -> Your project
Click Copy Dependency and select the libraries you need (TikTokOpenAuthSDK, TikTokOpenSDKCore, TikTokOpenShareSDK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants