Skip to content

Getting started with cross-promotion (Game Center)🔗

In order to integrate cross-promotion (Game Center) you need to follow these simple steps:

Step 1. Import cross-promotion module🔗

  • Add MRGSGameCenter module

    Unity:

    Adding to the project (general instruction)

    Step 1. Add Sources

    To add MRGS to a project via the Unity Package Manager (available from Unity 2018+) simply add a scopedRegistries section to the Packages/manifest.json file by adding the following entry:

    {
        "dependencies": {
            ...
        },
        "scopedRegistries": [
                {
                    "name": "MRGS",
                    "url": "https://mrgs-nexus.my.games/repository/mrgs-uninty-plugins/",
                    "scopes": [
                        "games.my.mrgs"
                    ]
                }
        ]
    }
    

    Alternatively, you can click Edit -> Project Settings -> Package Manager -> '+' in scoped registry section, and fill in the fields according to the data above.

    Step 2. Add dependency

    • Click Window -> Package Manager -> select 'Packages: MyRegistries' from dropdown list, select package MRGSGameCenter from the list, then click "Install"
    • Import the module: using MRGS;
    • Download the latest version of the library. Unzip the archive.
    • (For unitypackage integration) In Unity, click Assets -> Import Package -> Custom Package, and select the games.my.mrgs.gamecenter.unitypackage package from the downloaded archive.
    • (For tgz integration) In Unity, click Window -> Package Manager -> '+' -> Add package from tarball, and select the games.my.mrgs.gamecenter-<version> package. tgz from the downloaded archive.
    • Import the module: using MRGS;

    iOS:

    Adding to the project (general instruction)

    Step 1: Add dependencies

    Via Package collection

    • In Xcode select File > Add Packages
    • Select "+" > "Add Swift Package Collection"
    • Insert URL: https://mrgs-nexus.my.games/repository/ios-sdks/MRGSPackageCollection.json
    • Select module MRGSGameCenter from "MRGS Package Collection".
    • Or you can select "MRGS" package from "MRGS Package Collection" (contains all mrgs modules as products) and then select "MRGS/GameCenter" product only.

    Individual packages

    • In Xcode select File > Add Packages
    • In the search bar at the top right, paste the URL: https://mrgs-gitea.my.games/mrgs/mrgsgamecenter-ios-sdk.git
    • Add a module to your project
    • Or you can paste the url https://mrgs-gitea.my.games/mrgs/ios-sdks.git to include the "MRGS" package which contains all mrgs modules as products and then select only the product" MRGS/GameCenter".

    Step 2: Add support for ObjectiveC categories

    • Set the -ObjC flag in the "Other linker Flags" field in the project settings.
    • Import the module in code: @import MRGServiceKit; or @import MRGSGameCenter; or #import <MRGSGameCenter/MRGSGameCenter.h>

    Step 1. Add Sources

    In your podfile, add sources to the top of the file:

    source 'https://github.com/CocoaPods/Specs.git' # For main repo
    source 'https://mrgs-gitea.my.games/mrgs/cocoapods-specs.git'  # For MRGS repo
    

    Step 2: Add dependencies

    Add the latest version of MRGSGameCenter to target:

    To add via subspecs:

    target 'MyProject' do
        pod 'MRGS', '~> 5.0.0', :subspecs => ['GameCenter']
    end
    

    To add via individual modules:

    target 'MyProject' do
        pod 'MRGSGameCenter', '~> 5.0.0'
    end
    

    To add all mrgs modules:

    target 'MyProject' do
        pod 'MRGS/AllKits', '~> 5.0.0'
    end
    

    Step 3: Install dependencies

    • Run pod install (or pod install --repo-update if necessary)
    • Import the module in code: @import MRGServiceKit; or @import MRGSGameCenter; or #import <MRGSGameCenter/MRGSGameCenter.h>

    Step 1: Add dependencies

    Add the dependency to your Cartfile:

    binary "https://mrgs-nexus.my.games/repository/ios-sdks/MRGSGameCenter/MRGSGameCenter.json" ~> 5.0.0
    

    Step 2: Install dependencies

    • Run carthage update --use-xcframeworks
    • Add downloaded frameworks to your project (make sure "do not embed" option is enabled)
    • Set the -ObjC flag in the "Other linker Flags" field in the project settings.
    • Import the module in code: @import MRGServiceKit; or @import MRGSGameCenter; or #import <MRGSGameCenter/MRGSGameCenter.h>
    • Download the latest version of the library. Unzip the archive.
    • Add MRGSGameCenter.xcframework from the downloaded archive to your project (Drag the libraries to the "Linked frameworks and Libraries" section) (Also contains MRGSGameCenter.framework for compatibility - fat framework)

    • Add bundle with resources:

      • Add MRGSGameCenterResources.bundle to the project by dragging it into the project structure.
      • Go to the "Copy Bundle Resources" section in the "Build Phases" tab, click "+", and select the desired bundle.
    • Set the -ObjC flag in the "Other linker Flags" field in the project settings.

    • Import the module in code: @import MRGSGameCenter; or #import <MRGSGameCenter/MRGSGameCenter.h>
    • Also, you can add the MRGServiceKit.h and module.modulemap files from the archive to your project, or specify the path to them in the project settings in the Build Settings -> Header search paths section. Now, instead of importing each of our frameworks separately, you can only import one header file: @import MRGServiceKit;

    Android:

    Add a dependency in build.gradle file:

    dependencies {
        def mrgsVersion = "6.x.x"
    
        implementation "games.my.mrgs:gamecenter:$mrgsVersion"
    }
    

    Copy the MRGSGameCenter.aar file into the libs directory of your project. Add the necessary dependencies to the build.gradle file:

    dependencies {
        //...
        implementation(name: 'MRGSGameCenter', ext:'aar')
    
        implementation 'androidx.appcompat:appcompat:1.6.1'
        implementation 'androidx.recyclerview:recyclerview:1.2.1'
        implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
        implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    }
    

Step 2. Delegate setup🔗

Next you need to set up the MRGSGamecenterClientDelegate delegate to receive notifications.

// Where this - implementation of IMRGSGameCenterClientDelegate
MRGSGameCenter.Instance.Delegate = this;
[MRGSGameCenter sharedInstance].delegate = self; //Where self is an object that implements the MRGSGamecenterClientDelegate protocol
MRGSGameCenter.getInstance().setNewContentDelegate(this); //Where this is an object that implements the MRGSGameCenterNewContentDelegate protocol

Next, you need to implement the methods of the MRGSGamecenterClientDelegate delegate, that you've set earlier:

// Will be called when Game Center has something new and not yet seen by the user
// If this method is called, you need to mark the path to Game Center with circles in the game
public void OnGameCenterHasNewBonuses()
{
    // Show an invitation to open Game Center to the user
}
// Will be called when Game Center has something new and not yet seen by the user
//If this method is called, you need to mark the path to Game Center with circles in the game
-(void)gameCenterHasNewBonuses;
// Will be called when Game Center has something new and not yet seen by the user
//If this method is called, you need to mark the path to Game Center with circles in the game
public void onNewGCContent() {
    //Show an invitation to open Game Center to the user
}

This delegate is needed so that when it is called, you could show the user a notification, or mark the path to the showcase with markers, indicating that there are new offers for the user.

Step 3. Display the showcase🔗

Use the following method to display it:

MRGSGameCenter.Instance.Show();
- (void) showGameCenterfromViewController:(nullable UIViewController*)controller withSocialClassObject:(nullable MRGSGameCenterSocialClass*)socialInfo  completion:(void (^ __nullable)(BOOL))completion;

I.e:
[[MRGSGameCenter sharedInstance] showGameCenterfromViewController:self withSocialClassObject:socialInfoFromApp completion:^(BOOL _) {
    //This code will be executed after closing Game Center
}];
MRGSGameCenter.getInstance().open(this); // Where this is an Activitiy object

Make sure ads are set up on the server

During the first integration, if you receive a loading error, you need to make sure that creatives and campaigns are created on the MRGS server. In case of such problems, to check and launch test campaigns, please contact the contact indicated on the page with integration steps.

Example🔗

// Set a delegate
MRGSGameCenter.Instance.Delegate = this;

// ...
// Implementation of the delegate
public void OnGameCenterHasNewBonuses()
{
    // Here we use markers to indicate the path to the button that opens the showcase
}

// ...
// Call this method to show content:
MRGSGameCenter.Instance.Show();
// Delegate setup
[MRGSGameCenter sharedInstance].delegate = self;

// ...
// Delegate implementation
-(void)gameCenterHasNewBonuses{
    // Here we use markers to indicate the path to the button that opens the showcase
}

// ...
// Call this method to show content:
[[MRGSGameCenter sharedInstance] showGameCenterfromViewController:self withSocialClassObject:nil completion:^(BOOL _) {
    //This code will be executed after closing Game Center
}];
MRGSGameCenter.getInstance().setNewContentDelegate(this);

// Delegate implementation
public void onNewGCContent() {

}

// Call this method to show content:
MRGSGameCenter.getInstance().open(this);

Testing🔗

Since we update the data on new available campaigns every 12 hours since the last login to Game Center upon application launch, we added several methods of testing.

Use the following methods for testing:

// Clear server cache
// When testing the delegate, it is necessary that the delegate indicating new bonuses must be called when clearing the cache during the next launch
MRGSGameCenter.Instance.ClearCache()

// Clear downloaded data (images) of the campaigns
// This method can be used to test the "clean" launch of Game Center without pre-loaded data
MRGSGameCenter.Instance.ClearLoadedData()
// Clear the server cache
// When testing the delegate it is necessary that the delegate indicating new bonuses must be called when clearing the cache during the next launch
[[MRGSGameCenter sharedInstance] clearGameCenterCache];

// Clear the downloaded data (images) of the campaigns.
// This method can be used to test the "clean" launch of Game Center without pre-loaded data
[[MRGSGameCenter sharedInstance] clearGameCenterLoadedData];
// There is no need for implementation. It is enough to open the system settings, find the game in the list of applications, open the information on it and click the "Clear cache" button
What to do if there are problems with localization on iOS?

Localization issues may occur on iOS. We use native localization, therefore, it must be supported by the project. Thus, if you have problems with localization, check:

First option (more correct and promising):

  • Make sure there are at least Russian and English languages present in the localization menu item in the project settings
  • Make sure there is at least one Localizble.strings file (even if it's empty), and it is localized into Russian and English, and it is added to the build target (as a result there will be folders with language.lproj names in the assembled application)
  • The default project(XCode) localization language must be set to English.

Second option (manual indication of supported languages):

Add the following key into Info.plist of the application:

<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>ru</string>
</array>

Automatic key addition from the second option in Unity is described here.


Last update: 2023-10-25
Created: 2020-03-02