tiktok / tiktok-opensdk-ios

The TikTok OpenSDK features Login Kit and Share Kit which allow your users to log in using their TikTok account and share content from your app to TikTok.
https://developers.tiktok.com
Other
80 stars 31 forks source link

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

Open dorkyboi opened 1 year ago

dorkyboi commented 1 year ago

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 commented 1 year ago

https://github.com/tiktok/tiktok-opensdk-ios/issues/2#issuecomment-1623832120 (don't use cocoapods)

dorkyboi commented 1 year ago

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

nickdnk commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I don't use React Native, but it seems this a known problem with RN and something they're debating how to fix: https://github.com/react-native-community/discussions-and-proposals/issues/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 commented 1 year ago

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.

stephen-boyle commented 1 year ago

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

areejmayadeh commented 11 months ago

@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 commented 11 months ago

@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 commented 10 months ago

image

Nishannb commented 4 months ago

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

a7510774 commented 2 months ago

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

有最新消息吗?

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

Nishannb commented 2 months ago

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

a7510774 commented 2 months ago

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

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

Nishannb commented 2 months ago

@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 commented 1 month ago

@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)