I am trying to figure out how to use deep linking using cocox2dx (in c++) for iOS and Android.
Ideally a the user would click on a link which would open the app with a special parameter which someone gets passed into cocos2dx too so that i can check it do some specific stuff within my game.
I know that in iOS I have to modify the
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
And get the parameter directly from here and keep it somewhere (I am thinking the user defaults).
However I am very confused about where to handle the deep linking in android to pass it to Cocos2dx.
Thanks
energyy
December 19, 2015, 9:21am
#2
We recently integrated Deep Linking in Android & IOS, from facebook invite in our game.
So for IOS you need to write little part of native code and for Android same, use Bolt(from facebook ) framework for easier parsing of urls.
There is part which will help you with android:
Modify Androidmanifest.xml
<activity android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:name="org.cocos2dx.cpp.AppActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="yourschemaname" />
</intent-filter>
Modify this part <data android:scheme="yourschemaname" />
it will be your schema url on the web like yourschemaname://test?test=3453
Modify Appactivity:
@Override
protected void onResume() {
Uri targetUrl =
AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
if (targetUrl != null) {
// Log.i("ActivityMY", "App Link Target URL: " + targetUrl.toString());
Uri uri = getIntent().getData();
Uri parsedUri = Uri.parse(uri.toString());
String lidParamenter = parsedUri.getQueryParameter("test_id");
//Log.i("ActivityMY", "lidParamenter: " + lidParamenter);
if (lidParamenter != null){
if (lidParamenter.length() > 0){
SharedPreferences preferences = this.getSharedPreferences("Cocos2dxPrefsFile", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("FB_app_link_test_id",lidParamenter);
editor.commit();
AppLinks.getAppLinkData(getIntent()).clear();
}
}
}
else {
// Not an applink, your existing code goes here.
}
super.onResume();
// setImmersiveMode();
}
This part writes to NSDEFAULTS received parameters, just parse and write your needed parametrs, so you can access them from C++ code later on.
YOu can check how it works in game: https://play.google.com/store/apps/details?id=com.funlab.loop
From Creative Lounge login to facebook -> create new level -> Invite friend. Friend will receive Link which will navigate him to download page or will open game with your level.
1 Like