com.taptap.sdk.relation 4.10.4-beta.2 → 4.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,11 +13,16 @@ using System.Diagnostics;
13
13
  #if UNITY_IOS
14
14
  public class BuildPostProcessor
15
15
  {
16
+ private const string RELATION_URL_SCHEME_PREFIX = "tds";
17
+ private const string RELATION_URL_SCHEME_NAME = "TapTapRelation";
18
+
16
19
  [PostProcessBuild(999)]
17
20
  public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
18
21
  {
19
22
  if (buildTarget == BuildTarget.iOS)
20
23
  {
24
+ AddRelationURLScheme(path);
25
+
21
26
  var projPath = TapSDKCoreCompile.GetProjPath(path);
22
27
  var proj = TapSDKCoreCompile.ParseProjPath(projPath);
23
28
  var target = TapSDKCoreCompile.GetUnityTarget(proj);
@@ -53,6 +58,22 @@ public class BuildPostProcessor
53
58
  UnityEngine.Debug.LogWarning("TapRelation add Bundle Failed!");
54
59
  }
55
60
  }
56
-
61
+
62
+ private static void AddRelationURLScheme(string path)
63
+ {
64
+ var clientId = TapSDKCoreCompile.GetAppClientIdFromTDSInfo(Application.dataPath);
65
+ if (string.IsNullOrEmpty(clientId))
66
+ {
67
+ UnityEngine.Debug.LogError("TapRelation Can't find app.client_id in TDS-Info.json or taptap.client_id in fallback TDS-Info.plist!");
68
+ return;
69
+ }
70
+
71
+ TapSDKCoreCompile.AddURLSchemeToPlist(
72
+ Path.GetFullPath(path),
73
+ RELATION_URL_SCHEME_NAME,
74
+ RELATION_URL_SCHEME_PREFIX + clientId
75
+ );
76
+ }
77
+
57
78
  }
58
79
  #endif
@@ -4,12 +4,12 @@
4
4
  <repositories>
5
5
  <repository>https://repo.maven.apache.org/maven2</repository>
6
6
  </repositories>
7
- <androidPackage spec="com.taptap.sdk:tap-relation-unity:4.10.4-beta.2" />
7
+ <androidPackage spec="com.taptap.sdk:tap-relation-unity:4.10.4" />
8
8
  </androidPackages>
9
9
  <iosPods>
10
10
  <sources>
11
11
  <source>https://github.com/CocoaPods/Specs.git</source>
12
12
  </sources>
13
- <iosPod addToAllTargets="false" bitcodeEnabled="false" name="TapTapSDK/Relation" version="4.10.4-beta.2" />
13
+ <iosPod addToAllTargets="false" bitcodeEnabled="false" name="TapTapSDK/Relation" version="4.10.4" />
14
14
  </iosPods>
15
15
  </dependencies>
@@ -0,0 +1,221 @@
1
+ using System.Collections.Generic;
2
+ using System.IO;
3
+ using System.Xml;
4
+ using TapSDK.Core.Editor;
5
+ using UnityEditor.Android;
6
+ using UnityEngine;
7
+
8
+ namespace TapSDK.Relation.Mobile.Editor
9
+ {
10
+ public class TapRelationAndroidPostGenerateGradleProject : IPostGenerateGradleAndroidProject
11
+ {
12
+ private const string AndroidNamespaceUri = "http://schemas.android.com/apk/res/android";
13
+ private const string RouterActivityName = "com.taptap.sdk.relation.TapRelationRouterActivity";
14
+ private const string RouterActivityTheme = "@android:style/Theme.Translucent.NoTitleBar";
15
+ private static readonly string[] InviteHosts = { "invite_game", "invite_team" };
16
+
17
+ public int callbackOrder => 0;
18
+
19
+ public void OnPostGenerateGradleAndroidProject(string path)
20
+ {
21
+ string manifestPath = GetLauncherManifestPath(path);
22
+ if (string.IsNullOrEmpty(manifestPath) || !File.Exists(manifestPath))
23
+ {
24
+ Debug.LogWarning($"[TapSDK][Relation] AndroidManifest.xml not found under: {path}");
25
+ return;
26
+ }
27
+
28
+ var clientIds = ExtractClientIds();
29
+ if (clientIds.Count == 0)
30
+ {
31
+ Debug.LogWarning("[TapSDK][Relation] No clientId found, skip relation scheme intent-filter.");
32
+ return;
33
+ }
34
+
35
+ EnsureRelationRouterIntentFilters(manifestPath, clientIds);
36
+ }
37
+
38
+ private static string GetLauncherManifestPath(string exportPath)
39
+ {
40
+ string[] candidates =
41
+ {
42
+ Path.Combine(exportPath, "launcher", "src", "main", "AndroidManifest.xml"),
43
+ Path.Combine(exportPath, "src", "main", "AndroidManifest.xml")
44
+ };
45
+
46
+ foreach (string candidate in candidates)
47
+ {
48
+ if (File.Exists(candidate))
49
+ {
50
+ return candidate;
51
+ }
52
+ }
53
+
54
+ return null;
55
+ }
56
+
57
+ private static HashSet<string> ExtractClientIds()
58
+ {
59
+ var clientIds = new HashSet<string>();
60
+ var clientId = TapSDKCoreCompile.GetAppClientIdFromTDSInfo(Application.dataPath);
61
+ if (string.IsNullOrEmpty(clientId))
62
+ {
63
+ Debug.LogWarning("[TapSDK][Relation] app.client_id not found in TDS-Info.json or taptap.client_id not found in fallback TDS-Info.plist, skip relation scheme intent-filter.");
64
+ return clientIds;
65
+ }
66
+
67
+ clientIds.Add(clientId);
68
+ return clientIds;
69
+ }
70
+
71
+ private static void EnsureRelationRouterIntentFilters(string manifestPath, HashSet<string> clientIds)
72
+ {
73
+ var document = new XmlDocument();
74
+ document.Load(manifestPath);
75
+
76
+ XmlElement manifestElement = document.DocumentElement;
77
+ XmlElement applicationElement = manifestElement?.SelectSingleNode("application") as XmlElement;
78
+ if (applicationElement == null)
79
+ {
80
+ Debug.LogWarning($"[TapSDK][Relation] <application> node not found in manifest: {manifestPath}");
81
+ return;
82
+ }
83
+
84
+ XmlElement activityElement = FindActivity(applicationElement);
85
+ bool changed = false;
86
+ if (activityElement == null)
87
+ {
88
+ activityElement = document.CreateElement("activity");
89
+ activityElement.SetAttribute("name", AndroidNamespaceUri, RouterActivityName);
90
+ applicationElement.AppendChild(activityElement);
91
+ changed = true;
92
+ }
93
+
94
+ if (activityElement.GetAttribute("exported", AndroidNamespaceUri) != "true")
95
+ {
96
+ activityElement.SetAttribute("exported", AndroidNamespaceUri, "true");
97
+ changed = true;
98
+ }
99
+
100
+ if (activityElement.GetAttribute("noHistory", AndroidNamespaceUri) != "true")
101
+ {
102
+ activityElement.SetAttribute("noHistory", AndroidNamespaceUri, "true");
103
+ changed = true;
104
+ }
105
+
106
+ if (activityElement.GetAttribute("theme", AndroidNamespaceUri) != RouterActivityTheme)
107
+ {
108
+ activityElement.SetAttribute("theme", AndroidNamespaceUri, RouterActivityTheme);
109
+ changed = true;
110
+ }
111
+
112
+ foreach (string clientId in clientIds)
113
+ {
114
+ string scheme = "tds" + clientId;
115
+ foreach (string host in InviteHosts)
116
+ {
117
+ if (HasIntentFilter(activityElement, scheme, host))
118
+ {
119
+ continue;
120
+ }
121
+
122
+ activityElement.AppendChild(CreateIntentFilter(document, scheme, host));
123
+ changed = true;
124
+ }
125
+ }
126
+
127
+ if (changed)
128
+ {
129
+ SaveXml(document, manifestPath);
130
+ }
131
+ }
132
+
133
+ private static XmlElement FindActivity(XmlElement applicationElement)
134
+ {
135
+ foreach (XmlNode child in applicationElement.ChildNodes)
136
+ {
137
+ XmlElement element = child as XmlElement;
138
+ if (element == null || element.Name != "activity")
139
+ {
140
+ continue;
141
+ }
142
+
143
+ if (element.GetAttribute("name", AndroidNamespaceUri) == RouterActivityName)
144
+ {
145
+ return element;
146
+ }
147
+ }
148
+
149
+ return null;
150
+ }
151
+
152
+ private static bool HasIntentFilter(XmlElement activityElement, string scheme, string host)
153
+ {
154
+ foreach (XmlNode filterNode in activityElement.ChildNodes)
155
+ {
156
+ XmlElement filterElement = filterNode as XmlElement;
157
+ if (filterElement == null || filterElement.Name != "intent-filter")
158
+ {
159
+ continue;
160
+ }
161
+
162
+ foreach (XmlNode dataNode in filterElement.ChildNodes)
163
+ {
164
+ XmlElement dataElement = dataNode as XmlElement;
165
+ if (dataElement == null || dataElement.Name != "data")
166
+ {
167
+ continue;
168
+ }
169
+
170
+ if (dataElement.GetAttribute("scheme", AndroidNamespaceUri) == scheme &&
171
+ dataElement.GetAttribute("host", AndroidNamespaceUri) == host)
172
+ {
173
+ return true;
174
+ }
175
+ }
176
+ }
177
+
178
+ return false;
179
+ }
180
+
181
+ private static XmlElement CreateIntentFilter(XmlDocument document, string scheme, string host)
182
+ {
183
+ XmlElement intentFilter = document.CreateElement("intent-filter");
184
+
185
+ XmlElement action = document.CreateElement("action");
186
+ action.SetAttribute("name", AndroidNamespaceUri, "android.intent.action.VIEW");
187
+ intentFilter.AppendChild(action);
188
+
189
+ XmlElement defaultCategory = document.CreateElement("category");
190
+ defaultCategory.SetAttribute("name", AndroidNamespaceUri, "android.intent.category.DEFAULT");
191
+ intentFilter.AppendChild(defaultCategory);
192
+
193
+ XmlElement browsableCategory = document.CreateElement("category");
194
+ browsableCategory.SetAttribute("name", AndroidNamespaceUri, "android.intent.category.BROWSABLE");
195
+ intentFilter.AppendChild(browsableCategory);
196
+
197
+ XmlElement data = document.CreateElement("data");
198
+ data.SetAttribute("scheme", AndroidNamespaceUri, scheme);
199
+ data.SetAttribute("host", AndroidNamespaceUri, host);
200
+ intentFilter.AppendChild(data);
201
+
202
+ return intentFilter;
203
+ }
204
+
205
+ private static void SaveXml(XmlDocument document, string path)
206
+ {
207
+ var settings = new XmlWriterSettings
208
+ {
209
+ Indent = true,
210
+ IndentChars = " ",
211
+ NewLineChars = "\n",
212
+ NewLineHandling = NewLineHandling.Replace
213
+ };
214
+
215
+ using (XmlWriter writer = XmlWriter.Create(path, settings))
216
+ {
217
+ document.Save(writer);
218
+ }
219
+ }
220
+ }
221
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: b6a4f03a2c7a44eaa88ec97c8ef02c40
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -15,9 +15,16 @@ namespace TapSDK.Relation.Mobile
15
15
  {
16
16
  public class TapTapRelationImpl : ITapTapRelation
17
17
  {
18
+ #if UNITY_IOS
19
+ [DllImport("__Internal")]
20
+ private static extern void RegisterTapTapSDKRelationAppDelegateListener();
21
+ #endif
22
+
18
23
  private const string SERVICE_NAME = "BridgeRelationService";
19
24
  private static List<ITapTapRelationCallback> callbacks = new List<ITapTapRelationCallback>();
25
+ private static List<ITapTapRelationInviteCallback> inviteCallbacks = new List<ITapTapRelationInviteCallback>();
20
26
  private static bool hasRegisterCallBack = false;
27
+ private static bool hasRegisterInviteCallBack = false;
21
28
 
22
29
  public TapTapRelationImpl()
23
30
  {
@@ -28,7 +35,9 @@ namespace TapSDK.Relation.Mobile
28
35
 
29
36
  public void Init(string clientId, TapTapRegionType regionType, int screenOrientation)
30
37
  {
31
-
38
+ #if UNITY_IOS
39
+ RegisterTapTapSDKRelationAppDelegateListener();
40
+ #endif
32
41
  }
33
42
 
34
43
  public void StartMessenger()
@@ -175,13 +184,55 @@ namespace TapSDK.Relation.Mobile
175
184
  if (callback != null)
176
185
  {
177
186
  callbacks.Remove(callback);
187
+ if (callbacks.Count == 0 && hasRegisterCallBack)
188
+ {
189
+ var command = new Command.Builder()
190
+ .Service(SERVICE_NAME)
191
+ .Method("unregisterRelationCallback")
192
+ .Callback(false)
193
+ .OnceTime(false);
194
+ EngineBridge.GetInstance().CallHandler(command.CommandBuilder());
195
+ hasRegisterCallBack = false;
196
+ TapLog.Log("TapTapRelation UnregisterRelationCallback");
197
+ }
198
+ }
199
+ }
200
+
201
+ public void RegisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
202
+ {
203
+ if (callback == null) return;
204
+ InitRegisterInviteCallBack();
205
+ if (!inviteCallbacks.Contains(callback))
206
+ {
207
+ inviteCallbacks.Add(callback);
208
+ }
209
+ }
210
+
211
+ public void UnregisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
212
+ {
213
+ if (callback != null)
214
+ {
215
+ inviteCallbacks.Remove(callback);
216
+ if (inviteCallbacks.Count == 0 && hasRegisterInviteCallBack)
217
+ {
218
+ var command = new Command.Builder()
219
+ .Service(SERVICE_NAME)
220
+ .Method("unregisterRelationInviteCallback")
221
+ .Callback(false)
222
+ .OnceTime(false);
223
+ EngineBridge.GetInstance().CallHandler(command.CommandBuilder());
224
+ hasRegisterInviteCallBack = false;
225
+ TapLog.Log("TapTapRelation UnregisterRelationInviteCallback");
226
+ }
178
227
  }
179
228
  }
180
229
 
181
230
  public void Destroy()
182
231
  {
183
232
  callbacks.Clear();
233
+ inviteCallbacks.Clear();
184
234
  hasRegisterCallBack = false;
235
+ hasRegisterInviteCallBack = false;
185
236
  EngineBridge.GetInstance().CallHandler(new Command.Builder()
186
237
  .Service(SERVICE_NAME)
187
238
  .Method("destroy")
@@ -237,5 +288,50 @@ namespace TapSDK.Relation.Mobile
237
288
  });
238
289
  }
239
290
 
291
+ private void InitRegisterInviteCallBack()
292
+ {
293
+ if (hasRegisterInviteCallBack)
294
+ {
295
+ return;
296
+ }
297
+ hasRegisterInviteCallBack = true;
298
+
299
+ var command = new Command.Builder();
300
+ command.Service(SERVICE_NAME);
301
+ command.Method("registerRelationInviteCallback")
302
+ .Callback(true)
303
+ .OnceTime(false);
304
+ EngineBridge.GetInstance().CallHandler(command.CommandBuilder(), (result) =>
305
+ {
306
+ if (result.code != Result.RESULT_SUCCESS || string.IsNullOrEmpty(result.content))
307
+ {
308
+ return;
309
+ }
310
+
311
+ try
312
+ {
313
+ TapLog.Log("Relation Invite -->> Bridge Callback == " + JsonConvert.SerializeObject(result));
314
+ var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
315
+ var inviteType = SafeDictionary.GetValue<string>(dic, "invite_type");
316
+ var openId = SafeDictionary.GetValue<string>(dic, "open_id");
317
+ var unionId = SafeDictionary.GetValue<string>(dic, "union_id");
318
+ var teamId = SafeDictionary.GetValue<string>(dic, "team_id");
319
+
320
+ if (inviteType == "invite_team")
321
+ {
322
+ inviteCallbacks.ForEach(x => x.OnTeamInviteReceived(openId, unionId, teamId));
323
+ }
324
+ else if (inviteType == "invite_game")
325
+ {
326
+ inviteCallbacks.ForEach(x => x.OnGameInviteReceived(openId, unionId));
327
+ }
328
+ }
329
+ catch (Exception e)
330
+ {
331
+ TapLog.Error($"Relation invite callback parse result error: {e.Message}");
332
+ }
333
+ });
334
+ }
335
+
240
336
  }
241
- }
337
+ }
@@ -0,0 +1,37 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import <Foundation/Foundation.h>
3
+ #import <TapTapRelationSDK/TapTapRelationSDK-Swift.h>
4
+ #import "UnityAppController.h"
5
+ #import "AppDelegateListener.h"
6
+
7
+ @interface TapTapSDKRelationAppDelegateListener : NSObject<AppDelegateListener>
8
+
9
+ + (instancetype)sharedInstance;
10
+
11
+ @end
12
+
13
+ @implementation TapTapSDKRelationAppDelegateListener
14
+
15
+ + (instancetype)sharedInstance {
16
+ static TapTapSDKRelationAppDelegateListener *sharedInstance = nil;
17
+ static dispatch_once_t onceToken;
18
+ dispatch_once(&onceToken, ^{
19
+ sharedInstance = [[TapTapSDKRelationAppDelegateListener alloc] init];
20
+ });
21
+ return sharedInstance;
22
+ }
23
+
24
+ - (void)onOpenURL:(NSNotification *)notification {
25
+ NSDictionary *userInfo = notification.userInfo;
26
+ NSURL *url = [userInfo valueForKey:@"url"];
27
+ if (url) {
28
+ [TapTapRelation openWithUrl:url];
29
+ }
30
+ }
31
+
32
+ @end
33
+
34
+ extern "C" void RegisterTapTapSDKRelationAppDelegateListener() {
35
+ TapTapSDKRelationAppDelegateListener *listener = TapTapSDKRelationAppDelegateListener.sharedInstance;
36
+ UnityRegisterAppDelegateListener(listener);
37
+ }
@@ -0,0 +1,37 @@
1
+ fileFormatVersion: 2
2
+ guid: 5b490cb365244c4fa89b5c1851fca570
3
+ PluginImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ iconMap: {}
7
+ executionOrder: {}
8
+ defineConstraints: []
9
+ isPreloaded: 0
10
+ isOverridable: 0
11
+ isExplicitlyReferenced: 0
12
+ validateReferences: 1
13
+ platformData:
14
+ - first:
15
+ Any:
16
+ second:
17
+ enabled: 0
18
+ settings: {}
19
+ - first:
20
+ Editor: Editor
21
+ second:
22
+ enabled: 0
23
+ settings:
24
+ DefaultValueInitialized: true
25
+ - first:
26
+ iPhone: iOS
27
+ second:
28
+ enabled: 1
29
+ settings: {}
30
+ - first:
31
+ tvOS: tvOS
32
+ second:
33
+ enabled: 1
34
+ settings: {}
35
+ userData:
36
+ assetBundleName:
37
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 6045e07f1fd14e899f764516ef2169a8
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/Plugins.meta ADDED
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 3cb0dfb7c1f34f9f927a3f75f5a6a901
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -77,10 +77,20 @@ namespace TapSDK.Relation.Internal
77
77
  platformWrapper?.UnregisterRelationCallback(callback);
78
78
  }
79
79
 
80
+ public void RegisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
81
+ {
82
+ platformWrapper?.RegisterRelationInviteCallback(callback);
83
+ }
84
+
85
+ public void UnregisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
86
+ {
87
+ platformWrapper?.UnregisterRelationInviteCallback(callback);
88
+ }
89
+
80
90
  public void Destroy()
81
91
  {
82
92
  platformWrapper?.Destroy();
83
93
  }
84
94
  }
85
95
 
86
- }
96
+ }
@@ -16,7 +16,7 @@ namespace TapSDK.Relation
16
16
  void InviteTeam(string teamId);
17
17
 
18
18
  void ShowTapUserProfile(string openId, string unionId);
19
-
19
+
20
20
  void GetNewFansCount(Action<int> callback);
21
21
 
22
22
  void GetUnreadMessageCount(Action<int> callback);
@@ -25,6 +25,10 @@ namespace TapSDK.Relation
25
25
 
26
26
  void UnregisterRelationCallback(ITapTapRelationCallback callback);
27
27
 
28
+ void RegisterRelationInviteCallback(ITapTapRelationInviteCallback callback);
29
+
30
+ void UnregisterRelationInviteCallback(ITapTapRelationInviteCallback callback);
31
+
28
32
  void Destroy();
29
33
  }
30
- }
34
+ }
@@ -0,0 +1,9 @@
1
+ namespace TapSDK.Relation
2
+ {
3
+ public interface ITapTapRelationInviteCallback
4
+ {
5
+ void OnGameInviteReceived(string openId, string unionId);
6
+
7
+ void OnTeamInviteReceived(string openId, string unionId, string teamId);
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 9c2f56a153984e2db6c5ed752ca24f17
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -60,13 +60,23 @@ namespace TapSDK.Relation
60
60
  TapTapRelationManager.Instance.UnregisterRelationCallback(callback);
61
61
  }
62
62
 
63
+ public static void RegisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
64
+ {
65
+ TapTapRelationManager.Instance.RegisterRelationInviteCallback(callback);
66
+ }
67
+
68
+ public static void UnregisterRelationInviteCallback(ITapTapRelationInviteCallback callback)
69
+ {
70
+ TapTapRelationManager.Instance.UnregisterRelationInviteCallback(callback);
71
+ }
72
+
63
73
  public static void Destroy()
64
74
  {
65
75
  TapTapRelationManager.Instance.Destroy();
66
76
  }
67
77
 
68
78
 
69
- public static readonly string Version = "4.10.4-beta.2";
79
+ public static readonly string Version = "4.10.4";
70
80
 
71
81
 
72
82
  }
package/package.json CHANGED
@@ -2,11 +2,11 @@
2
2
  "name": "com.taptap.sdk.relation",
3
3
  "displayName": "TapTapSDK Relation",
4
4
  "description": "TapTapSDK Relation",
5
- "version": "4.10.4-beta.2",
5
+ "version": "4.10.4",
6
6
  "unity": "2019.4",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "com.taptap.sdk.core": "4.10.4-beta.2",
10
- "com.taptap.sdk.login": "4.10.4-beta.2"
9
+ "com.taptap.sdk.core": "4.10.4",
10
+ "com.taptap.sdk.login": "4.10.4"
11
11
  }
12
12
  }