Google Play Game Services(android)
実装方法
下記を参考に
https://developers.google.com/games/services/android/quickstart
ハマった点
BaseGameUtilsのimport
BaseGameUtilsをimportする際に
eclipse用のライブラリになっていない?
SYSTEM_KDのブログ: BaseGameUtilsをEclipseで使う
上記の対応でちゃんとimportできた
jar mismatch, fix your dependencies
java - jar mismatch, fix your dependencies - Stack Overflow
上記の問題が起こったので、
cp -p PATH_TO_FACRBOOK_SDK/facebook-android-sdk-3.20.0/facebook/libs/android-support-v4.jar PATH_TO_ANDROID_SAMPLES/android-basic-samples/eclipse_compat/libraries/BaseGameUtils/libs/android-support-v4.jar
Facebook SDKでcompletionGestureが来なくてハマった
Facebook SDKでシェアするため、下記の様な処理を書いた。
[FBDialogs presentShareDialogWithParams:shareParams clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { if (error) { NSLog(@"Error: %@", error.description); } else { NSLog(@"Success!"); NSLog(@"result %@", results); if([results objectForKey:@"didComplete"] && [[results objectForKey:@"completionGesture"]isEqualToString:@"post"]){ // フィード成功 [self successCallback]; } } }];
しかし、ちゃんとシェアしたのにcompletionGestureパラメータが入ってこないケースがあった。
これが無いとユーザが本当にシェアしたのか判定がうまく出来ない。
(シェアしても、キャンセルしても同じパラメータ)
調べてみると、入ってこないケースは下記のアプリ設定の中に、
実装したアプリが含まれていない場合だった。
https://www.facebook.com/settings?tab=applications
ではどうすれば良いのか、と言いますとログイン処理を書かねばいけない様だ。面倒ですね。
多分androidも同じです。
参考
ios - Detect successful facebook post using FBDialogs - Stack Overflow
AdMob組み込み
作業メモ
android
Setting Up Google Play Services | Android Developers
スタート ガイド - Google Mobile Ads SDK — Google Developers
広告のIDはActivityに書いてしまったので都度変える
ハマった所
http://blog.kojisblog.com/development/mobile-application/admob-compile-error/
frameworks/runtime-src/proj.android/project.properties
-target=android-10 +target=android-20
ios
スタート ガイド - Google Mobile Ads SDK — Google Developers
バナー 1 - Google Mobile Ads SDK — Google Developers
- 広告のIDはRootViewControllerに書いてしまったので都度変える
- 収益化するアプリ登録で、iosの方は開発中のアプリが検索できなかったので、アプリ名だけ入れてある
ハマった所
- コンパイルエラー
下記の問題が起きたので
objective c - Linking errors when adding AdMob to IOS cocos2d-x 3.2 - Stack Overflow
MediaPlayer.framework
GameController.framework
を追加
- viewDidLoad呼ばれない問題
RootViewController viewDidLoad
がcocos2dだと呼ばれないみたいなので
application didFinishLaunchingWithOptions
から呼び出すことにした
android課金処理
作業メモ
下記を参考に実装した
Selling In-app Products | Android Developers
下記の問題があったので対応
Android billing exception - Stack Overflow
Cocos2d-JS WebView連携
Cocos2d-JSはCocos2d-x v3.3rc0ベースなので下記の方が作成された仕組みが使えるはず!
cocos2d-x-3.x系で使えるWebView作った - 銀の人のメモ帳
と思ったのだがjsから叩けるインターフェースは未だ用意されていなかった。。。
のでbindingした話。
結果
こんな感じで一部webviewにすることが可能になった!
やり方
Cocos2d-JS v3.0 で他の言語とやり取り (JavaScript → C++ 編) | ましろいろのねこ
上記の方法を参考に下記のソースをbindingする
WebViewBridge.h
#ifndef WEBVIEWBRIDGE_H #define WEBVIEWBRIDGE_H #include <iostream> class WebViewBridge { public: static void addWebView(const std::string rootNodeName, const std::string webViewNodeName, float positionX, float positionY, float sizeX, float sizeY, const std::string loadURL, bool scalesPageToFit); }; #endif
WebViewBridge.cpp
#include "WebViewBridge.h" #include "cocos2d.h" #include "ui/CocosGUI.h" USING_NS_CC; void WebViewBridge::addWebView(const std::string rootNodeName, const std::string webViewNodeName, float positionX, float positionY, float sizeX, float sizeY, const std::string loadURL, bool scalesPageToFit){ auto webView = cocos2d::experimental::ui::WebView::create(); webView->setContentSize(Size(sizeX, sizeY)); webView->setPosition(Point(positionX, positionY)); webView->loadURL(loadURL); webView->setScalesPageToFit(scalesPageToFit); // js側で取得できるように名前をつける webView->setName(webViewNodeName); // コールバック関数を登録 webView->setOnShouldStartLoading( [](cocos2d::experimental::ui::WebView *sender, const std::string &url) { // TODO androidだと呼ばれないっぽい CCLOG("WebViewBridge OnShouldStartLoading"); return true; }); webView->setOnDidFinishLoading( [](cocos2d::experimental::ui::WebView *sender, const std::string &url) { CCLOG("WebViewBridge OnDidFinishLoading"); }); webView->setOnDidFailLoading( [](cocos2d::experimental::ui::WebView *sender, const std::string &url) { CCLOG("WebViewBridge setOnShouldStartLoading"); }); Scene* scene = Director::getInstance()->getRunningScene(); Node* root = scene->getChildByName(rootNodeName); root->addChild(webView); }
引数にObjectではなくstringでnode名などを渡しているのは、ジェネレート時にヘッダーファイルの解決でこけてしまうので止むなくこうしています。
補足
自分の場合、この仕組を使ってwebview内で自分で作ったアプリのリンク一覧のあるページを載せようと思っていました。
しかしandroidのwebviewで
market://
を踏んでも反応しない
http://play.google.com/...
なリンクも内部で展開されてしまう(そこからインストール出来ない)
ため、下記を参考に処理を加えました
frameworks/js-bindings/cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java
@Override public boolean shouldOverrideUrlLoading(WebView view, String urlString) { URI uri = URI.create(urlString); if (uri != null && uri.getScheme().equals(jsScheme)) { Cocos2dxWebViewHelper._onJsCallback(viewTag, urlString); return true; } // マーケットの場合はplay storeに飛ばす処理 START Uri _uri = Uri.parse(urlString); if (_uri.getScheme().equals("market") || (_uri.getScheme().startsWith("http") && _uri.getHost().equals("play.google.com"))) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(_uri); Activity host = (Activity) view.getContext(); host.startActivity(intent); return true; } catch (ActivityNotFoundException e) { Log.d(TAG, "shouldOverrideUrlLoading ActivityNotFoundException"); } } // マーケットの場合はplay storeに飛ばす処理 END return Cocos2dxWebViewHelper._shouldStartLoading(viewTag, urlString); }