Mac OSXおよびUnity2019.1.8f1でUnityでURLをパラメータとして取得するためのメソッドをmmファイルで記述しました
mm
1#import <Foundation/Foundation.h> 2#import "UnityAppController.h" 3 4 5// static な変数保持用 6@interface IntentParameter : NSObject 7+ (NSString*)getUrlString; 8+ (void)setUrlString:(NSString*)str; 9@end 10 11@implementation IntentParameter 12static id urlString = @""; 13+(NSString*)getUrlString{ 14 return urlString; 15} 16+(void)setUrlString:(NSString*)str{ 17 urlString = [str copy]; 18} 19@end 20 21 22// openURLをフックする処理 23@interface UrlHandlerAppController : UnityAppController 24@end 25 26@implementation UrlHandlerAppController 27- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { 28 29 [IntentParameter setUrlString:[url absoluteString]]; 30 31 return YES; 32} 33@end 34 35IMPL_APP_CONTROLLER_SUBCLASS(UrlHandlerAppController); 36 37 38// APIの定義 39extern "C"{ 40 const char* getUrlString(); 41} 42 43const char* getUrlString(){ 44 NSString *string = [IntentParameter getUrlString]; 45 const char *str = [string UTF8String]; 46 47 char* retStr = (char *)malloc(strlen(str) + 1); 48 strcpy(retStr, str); 49 return retStr; 50} 51
こちらをUnityEditorで動かすために下記のようなソースを組んだのですが、unity側ではエラー「EntryPointNotFoundException: getUrlString」が発生してしまいます。
C#(unity)
1public string url = "http://xxxxx/index.html"; //仮 2 3#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 4 [DllImport("__Internal")] 5 private static extern string getUrlString(); 6#endif 7 8 public static string GetUrlString(){ 9#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 10 return getUrlString(); 11#elif UNITY_IOS && !UNITY_EDITOR 12 return getUrlString(); 13#else 14 return "https://www.yahoo.co.jp/"; //暫定 15#endif 16 } 17 18void Start(){ 19#if UNITY_IOS && !UNITY_EDITOR 20 if (GetUrlString() != null) url = GetUrlString(); 21#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 22 if (GetUrlString() != null) url = GetUrlString(); 23#else 24 url = GetUrlString(); 25#endif 26//以下略
ひょっとしてビルドした先で動くのでは、と考えXcodeでiOS用のビルドを行い(こちらは成功)、アプリを実行させましたがdefineディレクティブが反応せずに#elseの「http://www.yahoo.co.jp」が選択されている状態です。
こちら、正しくdefineディレクティブを動作させ、mmファイルで設定したメソッドを動かすにはどのように設定を行えばよろしいでしょうか?
あなたの回答
tips
プレビュー