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

Add support for setting channelID afterwards #68

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions LINE_SDK_Unity/Assets/LineSDK/LineSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ void Awake() {
instance = this;
} else if (instance != this) {
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
SetupSDK();

if (!string.IsNullOrEmpty(channelID)) {
SetupSDK();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
Debug.LogWarning("LINE SDK channel ID is not set.");
}

Copy link
Member Author

@onevcat onevcat Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered to add an else here but decided not to do that finally. If we treat "leaving empty and calling Setup manually" as a possible and normal case, we should not produce a warning for this case.

Instead, an SDK error and/or the exception in Setup method will play the role of telling something goes wrong.

}

/// <summary>
Expand All @@ -64,9 +68,23 @@ public static LineSDK Instance {
}
}

void SetupSDK() {
/// <summary>
/// Initializes the native side of the SDK with the specified `channelID` in the prefab. This is only necessary
/// when you cannot determine and set the `channelID` in the Unity Editor at compiling time.
///
/// This method should be invoked only once per app session. If the `channelID` is already provided in the
/// prefab, `SetupSDK` is automatically triggered during the `Awake` method, eliminating the need for manual
/// invocation. However, if you need to assign different `channelID`s programmatically (for instance, in
/// varied environments like development or production), you can leave the `channelID` field empty in the
/// prefab, assign it in the code, and then call this method to finalize the SDK setup.
/// </summary>
/// <exception cref="Exception">
/// If the `channelID` is null or empty when this method is invoked, it will throw an exception. Ensure
/// the `channelID` is properly assigned before calling this method.
/// </exception>
public void SetupSDK() {
if (string.IsNullOrEmpty(channelID)) {
throw new System.Exception("LINE SDK channel ID is not set.");
throw new Exception("LINE SDK channel ID is not set.");
}
NativeInterface.SetupSDK(channelID, universalLinkURL);
}
Expand Down