Xamarin.iOS ã§ã¯ããã¤ãã£ããã¤ã³ãã£ã³ã°ã使ç¨ã㦠Objective-C ã§æ¸ãããã©ã¤ãã©ãªãå©ç¨ãããã¨ãã§ãã¾ãã
ã¤ã¾ããæ¢åã®Objective-Cã§æ¸ãããã¢ããªãXamarinã«ç§»è¡ããéãç¹å®ã®æ©è½ã¯ãã¤ãã£ãã©ã¤ãã©ãªã«ãããã¨ã§Objective-Cã®ã¾ã¾å©ç¨ãããã¨ãã§ãã¾ãã
ããã§ã¯ãObjective-Cã§æ¸ãããã¢ããªãUIViewControllerãã¨ãã¤ãã£ãã©ã¤ãã©ãªã«ããXamarin.iOSã«ãã¤ãã£ããã¤ã³ãã£ã³ã°ã§æã£ã¦ããæ¹æ³ããç´¹ä»ãã¾ãã
ããã¸ã§ã¯ãã®ä½æ
ä½æãããã¤ãã£ãã©ã¤ãã©ãªãå®éã«åä½ããã¦ç¢ºèªãã確èªç¨ã¢ããªãä½ãããã®ä¸ã«ä»åã®ç®æ¨ç©ãçæããã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªããã¸ã§ã¯ãã追å ããObjective-Cã§ç¢ºèªãã¦ããXamarinã«æã£ã¦è¡ãã¨å¹ççã§ãã
Xcode ããã¸ã§ã¯ãä½æ
ã¾ããXcode 㧠Empty Application ãä½æãã¾ãã
次ã«ãä½æããããã¸ã§ã¯ããå³ã¯ãªãã¯ããNew Project... ãé¸æãã¾ãã
ä»åº¦ã¯ Cocoa Touch Static Library ãæå®ãã¾ãããããXamarinã«æã£ã¦è¡ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã«ãªãã¾ãã
次ã«ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªããã¸ã§ã¯ãã® Build Settings ã«ãããBuild Active Architecture Only ã®æå®ãåé¤ããNo ã«ãã¾ãã
ãªã½ã¼ã¹ãã³ãã«ä½æã¿ã¼ã²ããã®è¿½å
次ã«ããã®ã©ã¤ãã©ãªã使ç¨ããç»åã»ããã¹ããªã©ã®ãªã½ã¼ã¹ãå«ã¾ãããã³ãã«ãä½æãã¾ãã
追å ãããã¤ãã£ãã©ã¤ãã©ãªã®ããã¸ã§ã¯ããé¸æããã¿ã¼ã²ããã®ãªã¹ãã®ä¸ã«ãã追å ãã¿ã³ãã¯ãªãã¯ãã¾ãã
iOS ã®ã»ãã«ã¯ Bundle ããªããããOS X ã®ã»ãã§è¿½å ãã¦ãã iOS ã«å¤æ´ããã¨ããæé ãè¸ã¿ã¾ããOS X ã® Frameworks & Library ãã Bundle ãé¸æãã¾ãããã®ã¨ããåå㯠ãã¤ãã£ãã©ã¤ãã©ãªã®åå + Resources ã¨ããå½¢ã«ãã¦ãã ããã(ãã®å¾ã§è¿½å ããã¹ã¯ãªããããããåæã«ä½ããã¦ãã¾ãã)
Build Settings 㧠Base SDK ã«è¨å®ããã¦ãã OS X ã®æå®ã delete ãã¼ã§æ¶ãã¾ãããããããã¨ã§ããã¸ã§ã¯ãå´ã«æå®ããã¦ãã iOS ã®æå®ã使ç¨ãããããã«ãªãã¾ãã
次ã«ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã®ã¿ã¼ã²ãããé¸ã³ãBuild Phases ã®ãã¼ã¸ã«ãã Target Dependencies ã«ãå ã»ã©ã®ãã³ãã«ãæå®ãã¾ããããã§ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã®ãã«ãæã«ãªã½ã¼ã¹ã®ãã³ãã«ãåæã«ä½æãããããã«ãªãã¾ãã
ã¦ããã¼ãµã«ãã¤ããªä½æã®ã¿ã¼ã²ãã追å
é常ãiOS ã¢ããªãã©ã¤ãã©ãªã¯ãå®æ©å®è¡ããã¨ãã¯å®æ©ç¨ãã·ãã¥ã¬ã¼ã¿å®è¡ããã¨ãã¯ã·ãã¥ã¬ã¼ã¿ç¨ã®ã©ã¤ãã©ãªã®ã¿ãåºåããã¾ããããã§ã¯ã·ãã¥ã¬ã¼ã¿å®è¡æã¨å®æ©å®è¡æã§å¥ã ã®DLLãåç §ããªãã¨ãããªããªã£ã¦ä¸ä¾¿ãªãããã¹ã¯ãªããã追å ãã¦å®æ©ç¨ã¨ã·ãã¥ã¬ã¼ã¿ç¨ã®ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªããããã¦1ã¤ã®ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã«ããå¦çãããã¸ã§ã¯ãã«è¿½å ãã¾ãã
å ã»ã©Bundleã追å ããã¨ãã¨åãæ¹æ³ã§ãiOS ã® Other ã«ãããAggregate ãé¸æãã¾ããèªåã¯ã©ã¤ãã©ãªå + Universal ã¨ååãã¤ãããã¨ãå¤ãã§ãã
Aggregate ã® Build Phase ã« Run Script Build Phase ã追å ãã¾ãã
追å ãããRun Script Build Phaseã«ä»¥ä¸ã®ã¹ã¯ãªãããå ¥åãã¾ãã
# define output folder environment variable LIBRARY_TARGET_NAME=${PROJECT_NAME} UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # Step 1. Build Device and Simulator versions xcodebuild -target "${LIBRARY_TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" xcodebuild -target "${LIBRARY_TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Step 2. Create universal binary file using lipo lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" # Last touch. copy the header files. Just for convenience cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/" cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${LIBRARY_TARGET_NAME}Resources.bundle" "${UNIVERSAL_OUTPUTFOLDER}/" open "${UNIVERSAL_OUTPUTFOLDER}/"
â»ãã®ã¹ã¯ãªããã¯Creating a Static Library in iOS Tutorial | Ray Wenderlichã«æ²è¼ããã¦ãããã®ã«å°ãæãå ¥ãããã®ã§ãã
確èªç¨ã¢ããªã®è¨å®
確èªç¨ã¢ããªããä½æããã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªãå©ç¨ã§ããããã«è¨å®ãã¾ãã
確èªç¨ã¢ããªã® Build Phases ã§ã以ä¸ã®ãããªè¨å®ãè¡ãã¾ãã
- Target Dependencies
- ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªããã³ãã«ã追å ãã¾ãã
- Link Binary With Libraries
- ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªãæå®ãã¾ãã
- Copy Bundle Resources
- ãã³ãã«ã追å ãã¾ãã
- ããã§ã¯è¿½å ãã¿ã³ããåç §ã§ããªããã¨ãããã¾ãããã®ã¨ã㯠Project Navigator ã® Products ã«ãããã³ãã«ã®é ç®ããããããã¦è¿½å ãã¦ãã ããã
æ¢åã¢ããªã®ã½ã¼ã¹ã®ããã¸ã§ã¯ãã¸ã®è¿½å
ãã¨ã¯æ¢åã®ã½ã¼ã¹ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã®ããã¸ã§ã¯ãã«è¿½å ãã¦ããã¾ãã
ã½ã¼ã¹ã³ã¼ãã¯ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªããªã½ã¼ã¹ã¯ãã³ãã«ãã¿ã¼ã²ããã«æå®ãã¾ãã
ã¾ããæ¢åã®ã½ã¼ã¹ã§ä½¿ç¨ãã¦ãããã¬ã¼ã ã¯ã¼ã¯ãªã©ã¯å¥éã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã«è¿½å ãã¦ããã¾ãã
追å ããã½ã¼ã¹ã®èª¿æ´
追å ããã½ã¼ã¹ã®ãã¡ãã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªã«ãããã¨ã«ãã調æ´ã¨ãXamarinå´ããå¼ã³åºãã¨ãã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ãæ´åãã¾ãã
ãªã½ã¼ã¹ã®èªã¿è¾¼ã¿ã®ä¿®æ£
ãªã½ã¼ã¹ã®èªã¿è¾¼ã¿é¨åã«ã¤ãã¦ãä¸è¨ã®ããã«ä¿®æ£ãã¾ãã
- NSBundle ãæå®ããèªã¿è¾¼ã¿ã®å ´åã[NSBundle mainBundle] ã nil ãæå®ãã¦ããé¨åã«ã©ã¤ãã©ãªã®ãã³ãã«ãæ示ãã¾ãã
- [UIImage imageNamed:] ã使ç¨ãã¦ããã¨ããã¯ããã¡ã¤ã«åã®å é ã«ãã³ãã«åãæå®ãã¾ãã ** [UIImage imageNamed:@"hoge.png"] â [UIImage imageNamed:@"EditorResources.bundle/hoge.png"]
ãã³ãã«ã使ç¨ããã¨ãã¯ãä¸è¨ã®ãããªã¯ã©ã¹ã¡ã½ãããç¨æããã¨ä¾¿å©ã§ãã
static NSBundle *editor_SharedBundle = nil; + (NSBundle *)bundle { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ editor_SharedBundle = [NSBundle bundleWithURL: [[NSBundle mainBundle] URLForResource:@"EditorResourcesâ withExtension:@"bundle"]]; }); return editor_SharedBundle; }
Xamarin å´ããå¼ã³åºãã¤ã³ã¿ã¼ãã§ã¤ã¹ãç¨æãã
èªåã§ä½ãã©ã¤ãã©ãªã¯å¤é¨ã«å ¬éããã¤ã³ã¿ã¼ãã§ã¤ã¹ãèªç±ã«ä½ããã¨ãã§ããã®ã§ãObjective Sharpieã«å¦çãããé¨åãæå°ã«ãããã¨ãã§ããã°ããã¤ãã£ããã¤ã³ãã£ã³ã°ãä½æããã¨ãã«æéãå°ãªãã§ãã
ããã§ãç»é¢ãã¼ã¹ã§æã£ã¦ããã®ã§ããã°å½è©²ã®UIViewControllerãä½æããã¯ã©ã¹ã ããå ¬éããã¨ããã§ãããã
#import "Editor.h" #import <UIKit/UIKit.h> @implementation Editor + (UIViewController *) editorViewController; @end
ããã¸ã§ã¯ãå ã§ã®ä½æ¥
ããã¸ã§ã¯ãå ã§ä½æ¥ãè¡ãã¨ãã¯ãã¿ã¼ã²ããã®æå®ã以ä¸ã®ããã«åãæ¿ãã¾ãã
- åä½ç¢ºèªãããã¨ãã¯ãµã³ãã«ã¢ããª
- ã¹ã¿ãã£ãã¯ã©ã¤ãã©ãªãä½æããã¨ã㯠Universal ã® Aggregate
- ãã®ã¨ããã¿ã¼ã²ããããã¤ã¹ã¯ iOS Device ã«åãããããã«ãã¦ãã ããã
ãã¤ãã£ããã¤ã³ãã£ã³ã°ã®ä½æ
ã¦ããã¼ãµã«ã©ã¤ãã©ãªãçæããã¨ãçæããããã¡ã¤ã«ãæ ¼ç´ããã¦ãããã©ã«ãã表示ããã¾ãã
ãã®ä¸ã® .a ãã¡ã¤ã«ã iOS Binding Project ã¸è¿½å ãã.h ãã¡ã¤ã«ã Objective Sharpie ã«èªã¿è¾¼ã¾ãã¦å®ç¾©çæãã¾ãã
ãã¤ãã£ããã¤ã³ãã£ã³ã°ã©ã¤ãã©ãªãã§ããããã¢ããªã®ããã¸ã§ã¯ãã«åç §è¨å®ã§è¿½å ããå¥éåºåããã¦ããbundleãããã¸ã§ã¯ãã«ãªã½ã¼ã¹ã¨ãã¦è¿½å ãã¾ãã
ãããã«
æ¢åã®ããã¸ã§ã¯ããXamarinã¸ç§»è¡ããéã¯ãä¸æ°ã«ãã¹ã¦C#ã§ãªãã¬ã¤ã¹ãã以å¤ã«ãã®ãããªãã¤ãã£ãã©ã¤ãã©ãªã使ç¨ãã¦æ¢åã®ã³ã¼ããæ´»ç¨ããªããå°ããã¤ããããæ¹æ³ãããã¾ããããã¸ã§ã¯ãã®ç§»è¡ã®éã¯æ¤è¨ãã¦ã¯ãããã§ããããã