Firebase-এ তৈরি Apple প্ল্যাটফর্মের গেমে প্লেয়ারদের সাইন-ইন করাতে আপনি গেম সেন্টার ব্যবহার করতে পারেন। Firebase-এর সাথে Game Center সাইন-ইন ব্যবহার করতে, প্রথমে নিশ্চিত করুন যে লোকাল প্লেয়ার Game Center-এ সাইন-ইন করেছেন এবং তারপর Firebase ক্রেডেনশিয়াল তৈরি করতে GameCenterAuthProvider অবজেক্ট ব্যবহার করুন, যা আপনি Firebase-এর সাথে যাচাই করতে ব্যবহার করতে পারবেন।
শুরু করার আগে
Firebase ডিপেন্ডেন্সি ইনস্টল ও ম্যানেজ করতে Swift প্যাকেজ ম্যানেজার ব্যবহার করুন।
আপনার Apple প্রোজেক্টে Firebase SDK যোগ করার বিভিন্ন উপায় সম্পর্কে জানতে- Xcode-এ, আপনার অ্যাপ প্রোজেক্ট খোলা রেখে, ফাইল > প্যাকেজ যোগ করুন বিকল্পে নেভিগেট করুন।
- প্রম্পট করা হলে, Firebase Apple প্ল্যাটফর্ম SDK রিপোজিটরি যোগ করুন:
- Firebase Authentication লাইব্রেরি বেছে নিন।
- আপনার টার্গেটের বিল্ড সেটিংসের অন্যান্য লিঙ্কার ফ্ল্যাগ বিভাগে
-ObjCফ্ল্যাগ যোগ করুন। - হয়ে গেলে, Xcode অটোমেটিক ব্যাকগ্রাউন্ডে আপনার ডিপেন্ডেন্সি সমাধান ও ডাউনলোড করা শুরু করবে।
https://github.com/firebase/firebase-ios-sdk.git
এরপর, কিছু কনফিগারেশন ধাপ সম্পূর্ণ করুন:
- Firebase-এ আপনার Apple অ্যাপ রেজিস্টার করেছেন কিনা তা ভাল করে দেখে নিন। এর অর্থ হল, রেজিস্ট্রেশন বিভাগে আপনার অ্যাপের বান্ডেল আইডি এবং এর সাথে অ্যাপ স্টোর আইডি ও টিম আইডির মতো অতিরিক্ত ঐচ্ছিক তথ্য লিখতে হবে। সাইন-ইন সম্পূর্ণ করার আগে ব্যবহারকারীর Game Center ক্রেডেনশিয়ালের দর্শককে নিরাপদে যাচাই করার জন্য এটি প্রয়োজন হবে।
- আপনার Firebase প্রোজেক্টের জন্য সাইন-ইন প্রদানকারী হিসেবে গেম সেন্টার চালু করুন:
- Firebase কনসোলে, নিরাপত্তা > যাচাইকরণ বিকল্পে যান।
- সাইন-ইন পদ্ধতি ট্যাবে, Game Center সাইন-ইন প্রদানকারী চালু করুন।
আপনার গেমে Game Center সাইন-ইন ইন্টিগ্রেট করা
প্রথমে, আপনার গেম যদি আগে থেকে গেম সেন্টার ব্যবহার না করে, তাহলে Apple ডেভেলপার সাইটে আপনার গেমে গেম সেন্টার অন্তর্ভুক্ত করা এবং ডিভাইসে স্থানীয় প্লেয়ারকে যাচাই করা সংক্রান্ত নির্দেশাবলী অনুসরণ করুন।
আপনি iTunes Connect-এ যে বান্ডেল আইডি দিয়েছেন সেটি আপনার Firebase প্রোজেক্টে অ্যাপ কানেক্ট করার সময় ব্যবহার করা বান্ডেল আইডির সাথে ম্যাচ করছে কিনা তা দেখে নিন।
আপনার গেম সেন্টার ইন্টিগ্রেশনের অংশ হিসেবে, আপনি একটি যাচাইকরণ হ্যান্ডলার নির্ধারণ করেন যা গেম সেন্টার যাচাইকরণ প্রক্রিয়ার একাধিক পয়েন্টে কল করা হয়। এই হ্যান্ডলারে, প্লেয়ার Game Center-এ সাইন-ইন করেছেন কিনা তা চেক করুন। যদি তাই হয়, তাহলে আপনি Firebase-এ সাইন-ইন করা চালিয়ে যেতে পারবেন।
Swift
let localPlayer = GKLocalPlayer.localPlayer() localPlayer.authenticateHandler = { (gcAuthViewController?, error) in if let gcAuthViewController = gcAuthViewController { // Pause any activities that require user interaction, then present the // gcAuthViewController to the player. } else if localPlayer.isAuthenticated { // Player is signed in to Game Center. Get Firebase credentials from the // player's Game Center credentials (see below). } else { // Error } }
Objective-C
__weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; localPlayer.authenticateHandler = ^(UIViewController *gcAuthViewController, NSError *error) { if (gcAuthViewController != nil) { // Pause any activities that require user interaction, then present the // gcAuthViewController to the player. } else if (localPlayer.isAuthenticated) { // Player is signed in to Game Center. Get Firebase credentials from the // player's Game Center credentials (see below). } else { // Error } };
Firebase-এর মাধ্যমে যাচাই করুন
আপনি যখন নির্ধারণ করবেন যে স্থানীয় প্লেয়ার Game Center-এ সাইন-ইন করেছেন,
তখন GameCenterAuthProvider.getCredential()-এর সাথে AuthCredential অবজেক্ট তৈরি করে এবং সেই অবজেক্ট signIn(with:)-এ পাস করে
আপনার গেমে প্লেয়ারকে সাইন-ইন করান:
Swift
// Get Firebase credentials from the player's Game Center credentials GameCenterAuthProvider.getCredential() { (credential, error) in if let error = error { return } // The credential can be used to sign in, or re-auth, or link or unlink. Auth.auth().signIn(with:credential) { (user, error) in if let error = error { return } // Player is signed in! }
Objective-C
// Get Firebase credentials from the player's Game Center credentials [FIRGameCenterAuthProvider getCredentialWithCompletion:^(FIRAuthCredential *credential, NSError *error) { // The credential can be used to sign in, or re-auth, or link or unlink. if (error == nil) { [[FIRAuth auth] signInWithCredential:credential completion:^(FIRUser *user, NSError *error) { // If error is nil, player is signed in. }]; } }];
পরবর্তী ধাপ
ব্যবহারকারী প্রথমবার সাইন-ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং তার Game Center আইডির সাথে লিঙ্ক করা হয়। এই নতুন অ্যাকাউন্ট আপনার Firebase প্রোজেক্টের অংশ হিসেবে স্টোর করা হয় এবং আপনার প্রোজেক্টের প্রতিটি অ্যাপ জুড়ে ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।
আপনার গেমে, আপনি User অবজেক্ট থেকে ব্যবহারকারীর Firebase UID পেতে পারেন:
Swift
let user = Auth.auth().currentUser if let user = user { let playerName = user.displayName // The user's ID, unique to the Firebase project. // Do NOT use this value to authenticate with your backend server, // if you have one. Use getToken(with:) instead. let uid = user.uid }
Objective-C
FIRUser *user = [FIRAuth auth].currentUser; if (user) { NSString *playerName = user.displayName; // The user's ID, unique to the Firebase project. // Do NOT use this value to authenticate with your backend server, // if you have one. Use getTokenWithCompletion:completion: instead. NSString *uid = user.uid; }
আপনার Firebase Realtime Database এবং Cloud Storage নিরাপত্তা নিয়মে, আপনি
সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি auth ভেরিয়েবল থেকে পেতে পারেন এবং এটি ব্যবহার করে
ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারবেন তা নিয়ন্ত্রণ করতে পারেন।
ব্যবহারকারীর গেম সেন্টার প্লেয়ারের তথ্য পেতে বা গেম সেন্টার পরিষেবা অ্যাক্সেস করতে, গেম কিট-এর মাধ্যমে প্রদান করা API ব্যবহার করুন।
Firebase থেকে কোনও ব্যবহারকারীকে সাইন-আউট করতে, Auth.signOut()-এ কল করুন:
Swift
let firebaseAuth = Auth.auth() do { try firebaseAuth.signOut() } catch let signOutError as NSError { print ("Error signing out: %@", signOutError) }
Objective-C
NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; if (!status) { NSLog(@"Error signing out: %@", signOutError); return; }