사전 준비
에셋 설치
![](https://t1.daumcdn.net/cfile/tistory/99B340335987D18A09)
유니티 코드
Firebase Invite API
void Start()
{
var app = Firebase.FirebaseApp.Create();
Firebase.Invites.FirebaseInvites.InviteReceived += OnInviteReceived;
Firebase.Invites.FirebaseInvites.InviteNotReceived += OnInviteNotReceived;
Firebase.Invites.FirebaseInvites.ErrorReceived += OnErrorReceived;
}
void OnInviteReceived(object sender,
Firebase.Invites.InviteReceivedEventArgs e)
{
if (e.InvitationId != "")
{
Debug.Log("Invite received: Invitation ID: " + e.InvitationId);
Firebase.Invites.FirebaseInvites.ConvertInvitationAsync(
e.InvitationId).ContinueWith(task =>
{
Debug.Log(string.Format("ConvertInvitationAsync::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted));
});
}
if (e.DeepLink != null)
{
Debug.Log("Invite received: Deep Link: " + e.DeepLink);
}
}
void OnInviteNotReceived(object sender, System.EventArgs e)
{
Debug.Log("No Invite or Deep Link received on start up");
}
void OnErrorReceived(object sender,
Firebase.Invites.InviteErrorReceivedEventArgs e)
{
Debug.LogError("Error occurred received the invite: " + e.ErrorMessage);
}
public void OnClickInvite()
{
var invite = new Firebase.Invites.Invite()
{
TitleText = "Invites Test App",
MessageText = "Please try my app! It's awesome.",
CallToActionText = "Download it for FREE",
DeepLinkUrl = new System.Uri("http://google.com/abc"),
CustomImageUrl = new System.Uri("http://lorempixel.com/400/200/")
};
FirebaseInvites.SendInviteAsync(invite).ContinueWith(sendTask =>
{
if (sendTask.IsCanceled)
{
Debug.Log("Invitation canceled.");
}
else if (sendTask.IsFaulted)
{
Debug.Log("Invitation encountered an error:");
Debug.Log(sendTask.Exception.ToString());
}
else if (sendTask.IsCompleted)
{
Firebase.Invites.SendInviteResult inviteResult = sendTask.Result;
foreach (string id in sendTask.Result.InvitationIds)
{
Debug.Log("SendInvite: Invite code: " + id);
}
}
});
}
실행한 화면
인증없이 바로 사용할 수 있다.
OnClickInvite()함수를 호출하면, 내장된 초대 UI가 나온다.
MessageText에 넣은 글과 이미지가 보이며,
수신자에 메일 계정 또는 전화번호도 입력할 수 있는 것 같지만,
전화번호는 테스트하지 않았다.
여러 명을 등록할 수 있었다.
![](https://t1.daumcdn.net/cfile/tistory/261316335980373F28)
초대코드가 정상적으로 남았다.
08-01 17:08:06.731: I/Unity(13678): SendInvite: Invite code: 1043398298368-75410820-eae5-4779-821a-1436add178cc
08-01 17:08:06.731: I/Unity(13678):
08-01 17:08:06.731: I/Unity(13678): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
메일을 확인했다.
글과 이미지 모두 정상적으로 보인다
![](https://t1.daumcdn.net/cfile/tistory/266734335980374001)
Install 이라는 링크를 클릭하니,
앱이 설치된 경우엔 앱이 실행되고,
아니면, 마켓으로 이동한다.
![](https://t1.daumcdn.net/cfile/tistory/270A3B33598037411A)
초청받은 사람이 메일에 있던 링크로 앱을 실행할 경우
OnInviteReceived함수가 호출된다.
링크로 앱을 실행할 경우 계속 호출된다.
초대받아서 들어온 사람에게 뭔가를 해야 한다면, 서버가 필요해 보인다.
08-01 17:41:03.586: I/Unity(15193): (InvitesClass) getInvitation:onResult:Status{statusCode=SUCCESS, resolution=null}
08-01 17:41:03.586: I/Unity(15193):
08-01 17:41:03.586: I/Unity(15193): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-01 17:41:03.806: I/Unity(15193): Invite received: Invitation ID: 1043398298368-75410820-eae5-4779-821a-1436add178cc
08-01 17:41:03.806: I/Unity(15193):
08-01 17:41:03.806: I/Unity(15193): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-01 17:41:03.826: I/Unity(15193): Invite received: Deep Link: http://google.com/abc
08-01 17:41:03.826: I/Unity(15193):
08-01 17:41:03.826: I/Unity(15193): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-01 17:41:04.266: I/Unity(15193): (InvitesClass) convertInvitation:onResult:Status{statusCode=SUCCESS, resolution=null}
08-01 17:41:04.266: I/Unity(15193):
08-01 17:41:04.266: I/Unity(15193): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-01 17:41:04.306: I/Unity(15193): ConvertInvitationAsync::IsCompleted:True IsCanceled:False IsFaulted:False
08-01 17:41:04.306: I/Unity(15193):
08-01 17:41:04.306: I/Unity(15193): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
링크로 앱을 실행하지 않는 경우
OnInviteNotReceived함수가 호출된다.
08-01 17:44:29.674: I/Unity(15292): (InvitesClass) getInvitation:onResult:Status{statusCode=CANCELED, resolution=null}
08-01 17:44:29.674: I/Unity(15292):
08-01 17:44:29.674: I/Unity(15292): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-01 17:44:29.704: I/Unity(15292): No Invite or Deep Link received on start up