Updated the 'BindingSample' sample (#339)

This commit is contained in:
Matthew Leibowitz 2019-01-16 19:51:51 +02:00 коммит произвёл Craig Dunn
Родитель df1b3e3a62
Коммит fd479f4d2d
77 изменённых файлов: 1180 добавлений и 1380 удалений

Просмотреть файл

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMBindingLibrary", "XMBindingLibrary\XMBindingLibrary.csproj", "{A62E63ED-97A6-475B-8376-912F2C027FAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMBindingLibrarySample", "XMBindingLibrarySample\XMBindingLibrarySample.csproj", "{0CDEA6B0-A495-48B0-ADC0-A6459F730571}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|Any CPU.Build.0 = Release|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Debug|iPhone.Build.0 = Debug|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|iPhone.ActiveCfg = Release|Any CPU
{A62E63ED-97A6-475B-8376-912F2C027FAB}.Release|iPhone.Build.0 = Release|Any CPU
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|Any CPU.Build.0 = Release|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhone.ActiveCfg = Debug|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhone.Build.0 = Debug|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhone.ActiveCfg = Release|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhone.Build.0 = Release|iPhone
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,5 +1,7 @@
all:
(cd src/binding/; make)
(cd NativeProject/; make)
msbuild
clean:
(cd src/binding; make clean)
(cd NativeProject/; make clean)
msbuild /t:clean

3
BindingSample/NativeProject/.gitignore поставляемый Executable file
Просмотреть файл

@ -0,0 +1,3 @@
xcuserdata/
build/
*.a

Просмотреть файл

@ -0,0 +1,30 @@
XBUILD=/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
PROJECT=XMBindingLibrary.xcodeproj
TARGET=XMBindingLibrary
all: libXMBindingLibraryUniversal.a
libXMBindingLibrary-i386.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -arch i386 -configuration Release clean build
-mv build/Release-iphonesimulator/lib$(TARGET).a $@
libXMBindingLibrary-armv7.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch armv7 -configuration Release clean build
-mv build/Release-iphoneos/lib$(TARGET).a $@
libXMBindingLibrary-x86_64.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -arch x86_64 -configuration Release clean build
-mv build/Release-iphonesimulator/lib$(TARGET).a $@
libXMBindingLibrary-arm64.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch arm64 -configuration Release clean build
-mv build/Release-iphoneos/lib$(TARGET).a $@
libXMBindingLibraryUniversal.a: libXMBindingLibrary-armv7.a libXMBindingLibrary-i386.a libXMBindingLibrary-arm64.a libXMBindingLibrary-x86_64.a
lipo -create -output $@ $^
clean:
-rm -rf *.a build/

Просмотреть файл

@ -0,0 +1,38 @@
XMBindingLibrary Native Project
======================================
This project contains the following items:
- XMBindingLibrary.xcodeproj
This is the Xcode project file.
- Makefile
The Makefile that will create a fat archive.
## Building the Native Library
To compile the Xcode Project and binding classes execute the `make` command from the root directory.
The make command will:
- Compile the Xcode Project for ARMv7, ARM64 (Devices), i386 and x86_64 (Simulators) using `xcodebuild`
- Create a multi-architecture binary using `lipo`
## Creating a Universal Binary
A "fat" or multi-architecture library is a compiled binary that is usable on multiple targets, for example: ARMv7, ARM64 (Devices), i386 and x86_64 (Simulators). In this sample we illustrate how to create a universal binary in two ways:
### Using lipo
Once we have built our library against the desired architectures we can create the universal binary via `lipo`. This will create a "universal" file from the architecture specific inputs we have provided. For instance:
lipo -create libNative-armv7.a libNative-arm64.a libNative-i386.a libNative-x86_64.a -output libNative.a
Similarly, in our Makefile script we have `lipo -create -output $@ $^` which will take the libraries compiled for ARM64, ARMv7, i386 and x86_64 using `xcodebuild` and output them to the current directory with the name of our build target.
### Using Xcode
In our Xcode project we have created a separate `Build Target` that will execute a post build `Run Script` to output a
"universal" file.
![screenshot](https://imgur.com/meVHNH4.png "Build Target - Run Script")

Двоичные данные
BindingSample/NativeProject/RunScript.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 298 KiB

Просмотреть файл

@ -1,114 +1,123 @@
# Version 2.0 (updated for Xcode 4, with some fixes)
# Changes:
# - Works with xcode 4, even when running xcode 3 projects (Workarounds for apple bugs)
# - Faster / better: only runs lipo once, instead of once per recursion
# - Added some debugging statemetns that can be switched on/off by changing the DEBUG_THIS_SCRIPT variable to "true"
# - Fixed some typos
#
# Purpose:
# Create a static library for iPhone from within XCode
# Because Apple staff DELIBERATELY broke Xcode to make this impossible from the GUI (Xcode 3.2.3 specifically states this in the Release notes!)
# ...no, I don't understand why they did this!
#
# Author: Adam Martin - http://twitter.com/redglassesapps
# Based on: original script from Eonil (main changes: Eonil's script WILL NOT WORK in Xcode GUI - it WILL CRASH YOUR COMPUTER)
#
# More info: see this Stack Overflow question: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
#################[ Tests: helps workaround any future bugs in Xcode ]########
#
DEBUG_THIS_SCRIPT="false"
if [ $DEBUG_THIS_SCRIPT = "true" ]
then
echo "########### TESTS #############"
echo "Use the following variables when debugging this script; note that they may change on recursions"
echo "BUILD_DIR = $BUILD_DIR"
echo "BUILD_ROOT = $BUILD_ROOT"
echo "CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR"
echo "BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR"
echo "CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR"
echo "TARGET_BUILD_DIR = $TARGET_BUILD_DIR"
fi
#####################[ part 1 ]##################
# First, work out the BASESDK version number (NB: Apple ought to report this, but they hide it)
# (incidental: searching for substrings in sh is a nightmare! Sob)
SDK_VERSION=$(echo ${SDK_NAME} | grep -o '.\{3\}$')
# Next, work out if we're in SIM or DEVICE
if [ ${PLATFORM_NAME} = "iphonesimulator" ]
then
OTHER_SDK_TO_BUILD=iphoneos${SDK_VERSION}
else
OTHER_SDK_TO_BUILD=iphonesimulator${SDK_VERSION}
fi
echo "XCode has selected SDK: ${PLATFORM_NAME} with version: ${SDK_VERSION} (although back-targetting: ${IPHONEOS_DEPLOYMENT_TARGET})"
echo "...therefore, OTHER_SDK_TO_BUILD = ${OTHER_SDK_TO_BUILD}"
#
#####################[ end of part 1 ]##################
#####################[ part 2 ]##################
#
# IF this is the original invocation, invoke WHATEVER other builds are required
#
# Xcode is already building ONE target...
#
# ...but this is a LIBRARY, so Apple is wrong to set it to build just one.
# ...we need to build ALL targets
# ...we MUST NOT re-build the target that is ALREADY being built: Xcode WILL CRASH YOUR COMPUTER if you try this (infinite recursion!)
#
#
# So: build ONLY the missing platforms/configurations.
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: I am NOT the root invocation, so I'm NOT going to recurse"
else
# CRITICAL:
# Prevent infinite recursion (Xcode sucks)
export ALREADYINVOKED="true"
echo "RECURSION: I am the root ... recursing all missing build targets NOW..."
echo "RECURSION: ...about to invoke: xcodebuild -configuration \"${CONFIGURATION}\" -target \"${TARGET_NAME}\" -sdk \"${OTHER_SDK_TO_BUILD}\" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO"
xcodebuild -configuration "${CONFIGURATION}" -target "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
ACTION="build"
#Merge all platform binaries as a fat binary for each configurations.
# Calculate where the (multiple) built files are coming from:
CURRENTCONFIG_DEVICE_DIR=${SYMROOT}/${CONFIGURATION}-iphoneos
CURRENTCONFIG_SIMULATOR_DIR=${SYMROOT}/${CONFIGURATION}-iphonesimulator
echo "Taking device build from: ${CURRENTCONFIG_DEVICE_DIR}"
echo "Taking simulator build from: ${CURRENTCONFIG_SIMULATOR_DIR}"
CREATING_UNIVERSAL_DIR=${SYMROOT}/${CONFIGURATION}-universal
echo "...I will output a universal build to: ${CREATING_UNIVERSAL_DIR}"
# ... remove the products of previous runs of this script
# NB: this directory is ONLY created by this script - it should be safe to delete!
rm -rf "${CREATING_UNIVERSAL_DIR}"
mkdir "${CREATING_UNIVERSAL_DIR}"
#
echo "lipo: for current configuration (${CONFIGURATION}) creating output file: ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"
lipo -create -output "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"
#########
#
# Added: StackOverflow suggestion to also copy "include" files
# (untested, but should work OK)
#
if [ -d "${CURRENTCONFIG_DEVICE_DIR}/usr/local/include" ]
then
mkdir -p "${CREATING_UNIVERSAL_DIR}/usr/local/include"
# * needs to be outside the double quotes?
cp "${CURRENTCONFIG_DEVICE_DIR}/usr/local/include/"* "${CREATING_UNIVERSAL_DIR}/usr/local/include"
fi
##########################################
#
# c.f. http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
#
# Version 2.82
#
# Latest Change:
# - MORE tweaks to get the iOS 10+ and 9- working
# - Support iOS 10+
# - Corrected typo for iOS 1-10+ (thanks @stuikomma)
#
# Purpose:
# Automatically create a Universal static library for iPhone + iPad + iPhone Simulator from within XCode
#
# Author: Adam Martin - http://twitter.com/redglassesapps
# Based on: original script from Eonil (main changes: Eonil's script WILL NOT WORK in Xcode GUI - it WILL CRASH YOUR COMPUTER)
#
set -e
set -o pipefail
#################[ Tests: helps workaround any future bugs in Xcode ]########
#
DEBUG_THIS_SCRIPT="false"
if [ $DEBUG_THIS_SCRIPT = "true" ]
then
echo "########### TESTS #############"
echo "Use the following variables when debugging this script; note that they may change on recursions"
echo "BUILD_DIR = $BUILD_DIR"
echo "BUILD_ROOT = $BUILD_ROOT"
echo "CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR"
echo "BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR"
echo "CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR"
echo "TARGET_BUILD_DIR = $TARGET_BUILD_DIR"
fi
#####################[ part 1 ]##################
# First, work out the BASESDK version number (NB: Apple ought to report this, but they hide it)
# (incidental: searching for substrings in sh is a nightmare! Sob)
SDK_VERSION=$(echo ${SDK_NAME} | grep -o '\d\{1,2\}\.\d\{1,2\}$')
# Next, work out if we're in SIM or DEVICE
if [ ${PLATFORM_NAME} = "iphonesimulator" ]
then
OTHER_SDK_TO_BUILD=iphoneos${SDK_VERSION}
else
OTHER_SDK_TO_BUILD=iphonesimulator${SDK_VERSION}
fi
echo "XCode has selected SDK: ${PLATFORM_NAME} with version: ${SDK_VERSION} (although back-targetting: ${IPHONEOS_DEPLOYMENT_TARGET})"
echo "...therefore, OTHER_SDK_TO_BUILD = ${OTHER_SDK_TO_BUILD}"
#
#####################[ end of part 1 ]##################
#####################[ part 2 ]##################
#
# IF this is the original invocation, invoke WHATEVER other builds are required
#
# Xcode is already building ONE target...
#
# ...but this is a LIBRARY, so Apple is wrong to set it to build just one.
# ...we need to build ALL targets
# ...we MUST NOT re-build the target that is ALREADY being built: Xcode WILL CRASH YOUR COMPUTER if you try this (infinite recursion!)
#
#
# So: build ONLY the missing platforms/configurations.
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: I am NOT the root invocation, so I'm NOT going to recurse"
else
# CRITICAL:
# Prevent infinite recursion (Xcode sucks)
export ALREADYINVOKED="true"
echo "RECURSION: I am the root ... recursing all missing build targets NOW..."
echo "RECURSION: ...about to invoke: xcodebuild -configuration \"${CONFIGURATION}\" -project \"${PROJECT_NAME}.xcodeproj\" -target \"${TARGET_NAME}\" -sdk \"${OTHER_SDK_TO_BUILD}\" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO" BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" SYMROOT=\"${SYMROOT}\"
xcodebuild -configuration "${CONFIGURATION}" -project "${PROJECT_NAME}.xcodeproj" -target "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}"
ACTION="build"
#Merge all platform binaries as a fat binary for each configurations.
# Calculate where the (multiple) built files are coming from:
CURRENTCONFIG_DEVICE_DIR=${SYMROOT}/${CONFIGURATION}-iphoneos
CURRENTCONFIG_SIMULATOR_DIR=${SYMROOT}/${CONFIGURATION}-iphonesimulator
echo "Taking device build from: ${CURRENTCONFIG_DEVICE_DIR}"
echo "Taking simulator build from: ${CURRENTCONFIG_SIMULATOR_DIR}"
CREATING_UNIVERSAL_DIR=${SYMROOT}/${CONFIGURATION}-universal
echo "...I will output a universal build to: ${CREATING_UNIVERSAL_DIR}"
# ... remove the products of previous runs of this script
# NB: this directory is ONLY created by this script - it should be safe to delete!
rm -rf "${CREATING_UNIVERSAL_DIR}"
mkdir "${CREATING_UNIVERSAL_DIR}"
#
echo "lipo: for current configuration (${CONFIGURATION}) creating output file: ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"
xcrun -sdk iphoneos lipo -create -output "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"
#########
#
# Added: StackOverflow suggestion to also copy "include" files
# (untested, but should work OK)
#
echo "Fetching headers from ${PUBLIC_HEADERS_FOLDER_PATH}"
echo " (if you embed your library project in another project, you will need to add"
echo " a "User Search Headers" build setting of: (NB INCLUDE THE DOUBLE QUOTES BELOW!)"
echo ' "$(TARGET_BUILD_DIR)/usr/local/include/"'
if [ -d "${CURRENTCONFIG_DEVICE_DIR}${PUBLIC_HEADERS_FOLDER_PATH}" ]
then
mkdir -p "${CREATING_UNIVERSAL_DIR}${PUBLIC_HEADERS_FOLDER_PATH}"
# * needs to be outside the double quotes?
cp -r "${CURRENTCONFIG_DEVICE_DIR}${PUBLIC_HEADERS_FOLDER_PATH}"* "${CREATING_UNIVERSAL_DIR}${PUBLIC_HEADERS_FOLDER_PATH}"
fi
fi

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "self:XMBindingLibrarySample.xcodeproj">
location = "self:">
</FileRef>
</Workspace>

Просмотреть файл

@ -2,9 +2,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>SnapshotAutomaticallyBeforeSignificantChanges</key>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Просмотреть файл

@ -1,9 +1,9 @@
//
// Prefix header for all source files of the 'XMBindingLibrarySample' target in the 'XMBindingLibrarySample' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#endif
//
// Prefix header for all source files of the 'XMBindingLibrary' target in the 'XMBindingLibrary' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#endif

Просмотреть файл

@ -1,24 +1,22 @@
//
// XMCustomView.h
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomViewDelegate.h"
@interface XMCustomView : UIView
{
}
@property (nonatomic, strong) NSString* name;
@property (nonatomic, assign) id <XMCustomViewDelegate> delegate;
-(void) customizeViewWithText:(NSString *)message;
@end
//
// XMCustomView.h
// XMBindingLibrary
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomViewDelegate.h"
@interface XMCustomView : UIView {
}
@property (nonatomic, strong) NSString* name;
@property (nonatomic, assign) id<XMCustomViewDelegate> delegate;
-(void) customizeViewWithText:(NSString *)message;
-(void) doTouch:(id<XMCustomViewDelegate>)delegate;
-(void) layoutSubviews;
@end

Просмотреть файл

@ -0,0 +1,62 @@
//
// XMCustomView.m
// XMBindingLibrary
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomView.h"
@implementation XMCustomView {
UILabel *txtView;
}
-(id) init {
if (self = [super init]) {
// create text box
txtView = [[UILabel alloc] init];
txtView.textAlignment = NSTextAlignmentCenter;
txtView.textColor = [UIColor blueColor];
txtView.lineBreakMode = NSLineBreakByWordWrapping;
txtView.adjustsFontSizeToFitWidth = NO;
txtView.numberOfLines = 0;
[self addSubview:txtView];
self.backgroundColor = [UIColor whiteColor];
// set inner shadow
self.layer.cornerRadius = 8;
self.layer.shadowOffset = CGSizeMake(10, 10);
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;
self.layer.shadowColor = [[UIColor blackColor] CGColor];
}
return self;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.delegate viewWasTouched:self];
}
-(void) customizeViewWithText:(NSString *)message {
if ([message length] > 0) {
txtView.text = message;
} else {
txtView.text = @"";
}
}
-(void) doTouch:(id<XMCustomViewDelegate>)delegate {
[delegate viewWasTouched:self];
}
- (void)layoutSubviews {
[super layoutSubviews];
txtView.frame = self.bounds;
}
@end

Просмотреть файл

@ -1,17 +1,16 @@
//
// XMCustomViewDelegate.h
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomView.h"
@protocol XMCustomViewDelegate<NSObject>
@required
-(void)viewWasTouched:(UIView *)view;
@end
//
// XMCustomViewDelegate.h
// XMBindingLibrary
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomView.h"
@protocol XMCustomViewDelegate<NSObject>
@required
-(void)viewWasTouched:(UIView *)view;
@end

Просмотреть файл

@ -1,26 +1,32 @@
//
// XMUtilities.h
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
// This is how to define a block function prototype.
typedef void (^XMUtilityCallback) (NSString *message);
@interface XMUtilities : NSObject {
XMUtilityCallback _callback;
}
-(id) init;
+(NSString *) echo:(NSString *)message;
-(NSString *) hello:(NSString *)name;
-(NSInteger) add:(NSInteger)operandUn and:(NSInteger) operandDeux;
-(NSInteger) multiply:(NSInteger)operandUn and:(NSInteger)operandDeux;
-(void) setCallback:(XMUtilityCallback) callback;
-(void) invokeCallback:(NSString *) message;
@end
//
// XMUtilities.h
// XMBindingLibrary
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
// This is how to define a block function prototype.
typedef void (^XMUtilityCallback) (NSString *message);
typedef NS_ENUM(NSInteger, XMGreeting) {
XMGreetingHello,
XMGreetingGoodbye,
};
@interface XMUtilities : NSObject {
}
-(id) init;
+(NSString *) echo:(NSString *)message;
-(NSString *) speak;
-(NSString *) speak:(XMGreeting)greeting;
-(NSString *) hello:(NSString *)name;
-(NSInteger) add:(NSInteger)operandUn and:(NSInteger) operandDeux;
-(NSInteger) multiply:(NSInteger)operandUn and:(NSInteger)operandDeux;
-(void) setCallback:(XMUtilityCallback) callback;
-(void) invokeCallback:(NSString *) message;
@end

Просмотреть файл

@ -1,74 +1,85 @@
//
// XMUtilities.m
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMUtilities.h"
@implementation XMUtilities
-(id) init
{
if(self = [super init]) {
// do initialization here after super init nil check!
}
return self;
}
-(void) dealloc
{
// this is an ARC project so we don't have to dealloc
// we dont even have to call [super dealloc];
// old habits die hard, Yippee-ki-yay!
}
// This is an example of a class method. It will echo the message you give it.
// Obj-C class methods are like C# static methods, but different.
+(NSString *) echo:(NSString *)message
{
if([message length] == 0) {
return [NSString stringWithFormat:@"Dude %@, you didnt give me a message!", @"bro"];
}
return [NSString stringWithFormat:@"%@", message];
}
// This is an example of an instance method.
-(NSString *) hello:(NSString *)name
{
if([name length] == 0) {
return [NSString stringWithFormat:@"Dude %@, you didnt give me a name!", @"bro"];
}
return [NSString stringWithFormat:@"*Waves* Hello %@! Welcome to the Xamarin binding sample!", name];
}
-(NSInteger) add:(NSInteger)operandUn and:(NSInteger) operandDeux
{
return operandUn + operandDeux;
}
-(NSInteger) multiply:(NSInteger)operandUn and:(NSInteger)operandDeux
{
return operandUn * operandDeux;
}
// This is an example of how to set a block function for later use.
-(void) setCallback:(XMUtilityCallback) callback
{
_callback = [callback copy];
}
// This is an example of how to invoke a block function.
-(void) invokeCallback:(NSString *) message
{
_callback (message);
}
@end
//
// XMUtilities.m
// XMBindingLibrary
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMUtilities.h"
@implementation XMUtilities {
XMUtilityCallback _callback;
}
-(id) init {
if (self = [super init]) {
// do initialization here after super init nil check!
}
return self;
}
-(void) dealloc {
// this is an ARC project so we don't have to dealloc
// we dont even have to call [super dealloc];
// old habits die hard, Yippee-ki-yay!
}
// This is an example of a class method. It will echo the message you give it.
// Obj-C class methods are like C# static methods, but different.
+(NSString *) echo:(NSString *)message {
if ([message length] == 0) {
return @"Yo, you didn't give me a message!";
}
return [NSString stringWithFormat:@"%@", message];
}
// This is an example of an instance method.
-(NSString *) speak {
return @"*Speaks* This is the Xamarin binding sample.";
}
-(NSString *) speak:(XMGreeting)greeting {
switch (greeting) {
case XMGreetingHello:
return @"*Speaks* This is a big HELLO!";
case XMGreetingGoodbye:
return @"*Speaks* This is a big GOODBYE!";
default:
return @"Yo, you didn't give me valid greeting!";
}
}
// This is an example of an instance method with a parameter.
-(NSString *) hello:(NSString *)name {
if ([name length] == 0) {
return @"Yo, you didn't give me a name!";
}
return [NSString stringWithFormat:@"*Waves* Hello %@! Welcome to the Xamarin binding sample!", name];
}
-(NSInteger) add:(NSInteger)operandUn and:(NSInteger) operandDeux {
return operandUn + operandDeux;
}
-(NSInteger) multiply:(NSInteger)operandUn and:(NSInteger)operandDeux {
return operandUn * operandDeux;
}
// This is an example of how to set a block function for later use.
-(void) setCallback:(XMUtilityCallback) callback {
_callback = [callback copy];
}
// This is an example of how to invoke a block function.
-(void) invokeCallback:(NSString *) message {
_callback (message);
}
@end

Просмотреть файл

@ -1,12 +1,10 @@
MonoTouch BTouch Binding Sample
Xamarin.iOS Binding Sample
===============================
This example shows how we can utilize an existing Objective-C library and expose it for use in a MonoTouch project. For instance, you may have existing code written in Objective-C that you may want to bind to C# to consume in your MonoTouch project. This sample provides a basic template/overview of the steps involved, including:
This example shows how we can utilize an existing Objective-C library and expose it for use in a Xamarin.iOS project. For instance, you may have existing code written in Objective-C that you may want to bind to C# to consume in your Xamarin.iOS project. This sample provides a basic template/overview of the steps involved, including:
- Creating a "fat" or multi-architecture library that can be target both the iOS simulator and device.
- Defining an API definition file in the form of a C# interface against the Objective-C API.
- Building a `*.dll` that contains both the binding and and the embedded native library.
## Understanding this Sample
@ -14,43 +12,7 @@ This example shows how we can utilize an existing Objective-C library and expose
This sample consists of three distinct source projects:
- Xcode Project in Objective-C
- MonoTouch Binding classes
- MonoTouch Sample Project
- Xamarin.iOS Binding classes
- Xamarin.iOS Sample Project
Please see the README in each project folder for more details.
## Building this Sample
To compile the Xcode Project and binding classes execute the `make` command from the root directory.
The make command will:
- Compile the Xcode Project for ARMv7, ARM64, and i386 (Simulator)
- Create a multi-architecture binary using `lipo`
- Create a `*.dll` in the binding folder using `btouch-native`
The resulting .dll is created using the [LinkWithAttribute](http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types#Linking_the_Dependencies) and will automatically embed the native library in your application.
## Creating a Universal Binary
A "fat" or multi-architecture library is a compiled binary that is usable on
multiple targets, for example: ARMv7, ARM64, and i386 (simulator). In
this sample we illustrate how to create a universal binary in two ways:
### Using lipo
Once we have built our library against the desired architectures we can create the universal binary via `lipo`. This will create a "universal" file from the architecture specific inputs we have provided. For instance:
lipo -create libXMBindingLibrarySample-armv7.a libXMBindingLibrarySample-arm64.a libXMBindingLibrarySample-i386.a -output libXMBindingLibrarySampleUniversal.a
Similarly, in our Makefile script we have `lipo -create -output $@ $^` which will take the libraries compiled for ARM64, ARMv7, and i386 using xbuild and output them to the current directory with the name of our build target.
### Using Xcode
In our Xcode project we have created a separate `Build Target` that will execute a post build `Run Script` to output a
"universal" file.
![screenshot](http://i.imgur.com/6SIsx.png "Build Target - Run Script")
This Run Script is also available for reference in the "Post-Build Run Script" group of the Xcode project.

Двоичные данные
BindingSample/Screenshots/01.png Executable file → Normal file

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 111 KiB

После

Ширина:  |  Высота:  |  Размер: 141 KiB

Двоичные данные
BindingSample/Screenshots/02.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 140 KiB

Просмотреть файл

@ -0,0 +1,131 @@
using System;
using Foundation;
using ObjCRuntime;
using UIKit;
namespace XMBindingLibrary
{
// typedef void (^XMUtilityCallback) (NSString *message);
public delegate void XMUtilityCallback(NSString message);
// @interface XMUtilities : NSObject
[BaseType(typeof(NSObject))]
interface XMUtilities
{
// NOTE:
// We DO NOT have to bind a constructor since the default/empty
// constructor will be automatically generated.
//
// -(id) init;
//[Export("init")]
//IntPtr Constructor();
// NOTE:
// This is attributed with static because it is a class/static method.
//
// +(NSString *) echo:(NSString *)message;
[Static]
[Export("echo:")]
string Echo(string message);
// NOTE:
// Methods without a parameter do not need the trailing colon (":").
//
// -(NSString *) speak;
[Export("speak")]
string Speak();
// -(NSString *) speak:(XMGreeting)greeting;
[Export("speak:")]
string Speak(XMGreeting greeting);
// NOTE:
// Methods WITH a parameter must have a trailing colon (":").
//
// -(NSString *) hello:(NSString *)name;
[Export("hello:")]
string Hello(string name);
// NOTE:
// Here we have two parameters, and the method name
// and each argument are suffxed with a colon.
//
// -(NSInteger) add:(NSInteger)operandUn and:(NSInteger) operandDeux;
[Export("add:and:")]
nint Add(nint operandUn, nint operandDeux);
// -(NSInteger) multiply:(NSInteger)operandUn and:(NSInteger)operandDeux;
[Export("multiply:and:")]
nint Multiply(nint operandUn, nint operandDeux);
// -(void) setCallback:(XMUtilityCallback) callback;
[Export("setCallback:")]
void SetCallback(XMUtilityCallback callback);
// -(void) invokeCallback:(NSString *) message;
[Export("invokeCallback:")]
void InvokeCallback(string message);
}
// NOTE:
// We create a dummy I<DelegateName> here so we can reference it from the
// delegate prperty and other members.
interface IXMCustomViewDelegate { }
// @protocol XMCustomViewDelegate<NSObject>
[Protocol]
[Model(AutoGeneratedName = true)]
[BaseType(typeof(NSObject))]
interface XMCustomViewDelegate
{
// NOTE:
// The [Abstract] attribute is added since this is a required member.
//
// @required -(void)viewWasTouched:(UIView *)view;
[Abstract]
[Export("viewWasTouched:")]
void ViewWasTouched(XMCustomView view);
}
// NOTE:
// We want to turn the delegate members into events, so we set the
// attribute's "Delegates" property to the delegate property name
// And, we set the attribute's "Events" property to the type of the
// delegate.
//
// @interface XMCustomView : UIView
[BaseType(typeof(UIView),
Delegates = new[] { "Delegate" },
Events = new[] { typeof(XMCustomViewDelegate) })]
interface XMCustomView
{
// @property (nonatomic, strong) NSString* name;
[Export("name")]
string Name { get; [NullAllowed] set; }
// NOTE:
// Instead of using the class type, we use the interface as this will
// be more flexible.
//
// @property (nonatomic, assign) id<XMCustomViewDelegate> delegate;
[Export("delegate", ArgumentSemantic.Assign)]
[NullAllowed]
IXMCustomViewDelegate Delegate { get; set; }
// NOTE:
// The C# method name does not have to match the Objective-C name
// because the attribute will be used to find it.
//
// -(void) customizeViewWithText:(NSString *)message;
[Export("customizeViewWithText:")]
void CustomizeView(string message);
// NOTE:
// This method uses the dummy interface because it accepts a protocol
// and not a concrete type.
//
// -(void) doTouch:(id<XMCustomViewDelegate>)delegate;
[Export("doTouch:")]
void DoTouch(IXMCustomViewDelegate del);
}
}

Просмотреть файл

@ -13,10 +13,11 @@
</PropertyGroup>
<Target Name="CleanResources">
<Exec Command="make clean" WorkingDirectory="..\..\..\binding" />
<Exec Command="make clean" WorkingDirectory="..\NativeProject" />
</Target>
<Target Name="PrepareResources">
<Exec Command="make" WorkingDirectory="..\..\..\binding" />
<Exec Command="make" WorkingDirectory="..\NativeProject" />
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,15 @@
using System;
namespace XMBindingLibrary
{
partial class XMUtilities
{
// NOTE:
// We can add additional members in this file that were never in the
// original binding.
public nint Subtract(nint operandUn, nint operandDeux)
{
return Add(operandUn, -operandDeux);
}
}
}

Просмотреть файл

@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Foundation;
// This attribute allows you to mark your assemblies as “safe to link”.
// When the attribute is present, the linker—if enabled—will process the assembly
// even if youre using the “Link SDK assemblies only” option, which is the default for device builds.
[assembly: LinkerSafe]
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("XMBindingLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Author 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

Просмотреть файл

@ -0,0 +1,17 @@
XMBindingLibrary Binding Project
======================================
This project contains the following items:
- Extras.cs
This is where we define the partial types for our interface definitions.
- ApiDefinition.cs
The API definition file which contains the interfaces which have been attributed to drive the binding.
- Structs.cs
The enumerations and structs file which contains any non Objective-C types.
- BindingActions.targets
The MSBuild targets file that will make sure the native library is built before trying to bind it.
## Building the Binding Library
The resulting assembly is created using [Native References](https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/native-references) and will automatically embed the native library in your application.

Просмотреть файл

@ -0,0 +1,8 @@
namespace XMBindingLibrary
{
public enum XMGreeting
{
Hello,
Goodbye,
}
}

Просмотреть файл

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A62E63ED-97A6-475B-8376-912F2C027FAB}</ProjectGuid>
<ProjectTypeGuids>{8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>XMBindingLibrary</RootNamespace>
<AssemblyName>XMBindingLibrary</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Extras.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingCoreSource Include="Structs.cs" />
</ItemGroup>
<ItemGroup>
<NativeReference Include="..\NativeProject\libXMBindingLibraryUniversal.a">
<Kind>Static</Kind>
<ForceLoad>True</ForceLoad>
</NativeReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
<Import Project="BindingActions.targets" />
</Project>

2
BindingSample/XMBindingLibrarySample/.gitignore поставляемый Executable file
Просмотреть файл

@ -0,0 +1,2 @@
bin/
obj/

Просмотреть файл

@ -0,0 +1,25 @@
using Foundation;
using UIKit;
namespace XMBindingLibrarySample
{
[Register(nameof(AppDelegate))]
public partial class AppDelegate : UIApplicationDelegate
{
RootViewController rootViewController;
public override UIWindow Window { get; set; }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
rootViewController = new RootViewController();
Window.RootViewController = rootViewController;
Window.MakeKeyAndVisible();
return true;
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
@ -35,11 +35,15 @@
<string>Binding Library Sample</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.bindinglibrarysample</string>
<key>CFBundleShortVersionString</key>
<string>01.00</string>
<key>CFBundleVersion</key>
<string>01</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<key>CFBundleName</key>
<string>Binding Library Sample</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,13 @@
using UIKit;
namespace XMBindingLibrarySample
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
UIApplication.Main(args, null, nameof(AppDelegate));
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@
XMBindingLibrarySample Sample Application
================
This project contains our Xamarin.iOS sample. It has a reference to XMBindingLibrary.dll and makes calls to our native library written in Objective-C from C#.
Example:
var utility = new XMUtilities();
var result = utility.Hello("Developer");
Console.WriteLine(result);

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 5.2 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 12 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Просмотреть файл

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="199">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<scene sceneID="198">
<objects>
<viewController id="199" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="196"/>
<viewControllerLayoutGuide type="bottom" id="197"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="200">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace" white="0" alpha="1"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="203" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" image="Default.png">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" heightSizable="YES" widthSizable="YES"/>
</imageView>
</subviews>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="201" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="935" y="454"/>
</scene>
</scenes>
<resources>
<image name="Default.png" width="320" height="480"/>
</resources>
</document>

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 106 KiB

После

Ширина:  |  Высота:  |  Размер: 106 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 273 KiB

После

Ширина:  |  Высота:  |  Размер: 273 KiB

Просмотреть файл

@ -0,0 +1,120 @@
using System;
using CoreGraphics;
using Foundation;
using MonoTouch.Dialog;
using UIKit;
using XMBindingLibrary;
namespace XMBindingLibrarySample
{
public class CustomViewController : DialogViewController
{
XMCustomView customView;
public CustomViewController()
: base(new RootElement("XMCustomView Binding") { UnevenRows = true }, true)
{
}
public override void LoadView()
{
base.LoadView();
customView = new XMCustomView
{
// The XMCustomView Name Property
Name = "Xamarin User",
// The instance method uses a frame calculation.
Frame = new CGRect(10, 10, View.Bounds.Width - 40, 150),
};
// This is the custom event we bound.
// This is sometimes preferable to specifying a delegate.
customView.ViewWasTouched += Handle_CustomViewViewWasTouched;
// The XMCustomViewDelegate we bound
// If we specify this it will OVERRIDE the event handler we specified
// customView.Delegate = new CustomViewDelegate();
// The instance method we bound.
customView.CustomizeView($"Yo {customView.Name}, I heard you like bindings! Xamarin makes it super easy with binding projects. Try it out!");
Root.Add(new[]
{
new Section("Custom View")
{
new UIViewElement("", customView, true, new UIEdgeInsets(0, 0, 40, 40)),
},
new Section("Operations")
{
new StringElement("Use Event", Handle_UseEvent),
new StringElement("Use Delegate", Handle_UseDelegate),
new StringElement("Do Touch", Handle_DoTouchOperation),
}
});
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
NavigationItem.HidesBackButton = false;
NavigationItem.BackBarButtonItem = new UIBarButtonItem("Utilities", UIBarButtonItemStyle.Plain, null);
}
void Handle_UseEvent()
{
customView.Delegate = null;
// attach the event
customView.ViewWasTouched += Handle_CustomViewViewWasTouched;
}
void Handle_UseDelegate()
{
// set the delegate
customView.Delegate = new CustomViewDelegate(this);
}
void Handle_DoTouchOperation()
{
using (var temp = new CustomViewDelegate(this))
{
customView.DoTouch(temp);
}
}
void Handle_CustomViewViewWasTouched(object sender, EventArgs e)
{
Handle_ViewTouched("EVENT");
}
void Handle_ViewTouched(string where)
{
NSThread.Current.BeginInvokeOnMainThread(() =>
{
var vc = UIAlertController.Create("Touched", $"Our bound XMCustomView was touched from the {where}!", UIAlertControllerStyle.Alert);
vc.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
PresentViewController(vc, true, null);
});
}
class CustomViewDelegate : XMCustomViewDelegate
{
CustomViewController viewController;
public CustomViewDelegate(CustomViewController viewController)
{
this.viewController = viewController;
}
public override void ViewWasTouched(XMCustomView view)
{
viewController.Handle_ViewTouched("DELEGATE");
}
}
}
}

Просмотреть файл

@ -0,0 +1,23 @@
using UIKit;
namespace XMBindingLibrarySample
{
public class RootViewController : UINavigationController
{
UtilitiesViewController utilViewController;
public override void LoadView()
{
base.LoadView();
utilViewController = new UtilitiesViewController();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
PushViewController(utilViewController, true);
}
}
}

Просмотреть файл

@ -0,0 +1,138 @@
using Foundation;
using MonoTouch.Dialog;
using XMBindingLibrary;
namespace XMBindingLibrarySample
{
public class UtilitiesViewController : DialogViewController
{
XMUtilities utility;
public UtilitiesViewController()
: base(new RootElement("XMUtilities Binding"), true)
{
}
public override void LoadView()
{
base.LoadView();
utility = new XMUtilities();
utility.SetCallback(new XMUtilityCallback(message =>
{
SetResultElementValue("Callback: " + message);
}));
Root.Add(new[]
{
new Section("Operands")
{
new EntryElement("Name: ", "", ""),
new EntryElement("Operand One: ", "", ""),
new EntryElement("Operand Two: ", "", ""),
},
new Section("Result")
{
new StringElement("")
},
new Section("Operations")
{
new StringElement("Add", Handle_AddOperation),
new StringElement("Subtract", Handle_SubtractOperation),
new StringElement("Multiply", Handle_MultiplyOperation),
new StringElement("Echo", Handle_EchoOperation),
new StringElement("Speak", Handle_SpeakOperation),
new StringElement("Speak Greeting", Handle_SpeakGreetingOperation),
new StringElement("Hello", Handle_HelloOperation),
new StringElement("Invoke Callback", Handle_InvokeCallback),
},
new Section("More Bindings")
{
new StringElement("Go to CustomView!", () =>
{
var c = new CustomViewController();
NavigationController.PushViewController(c, true);
})
}
});
}
void Handle_AddOperation()
{
var one = Root[0][1] as EntryElement;
var two = Root[0][2] as EntryElement;
int.TryParse(one.Value, out var un);
int.TryParse(two.Value, out var deux);
SetResultElementValue($"{utility.Add(un, deux)}");
}
void Handle_SubtractOperation()
{
var one = Root[0][1] as EntryElement;
var two = Root[0][2] as EntryElement;
int.TryParse(one.Value, out var un);
int.TryParse(two.Value, out var deux);
SetResultElementValue($"{utility.Subtract(un, deux)}");
}
void Handle_MultiplyOperation()
{
var one = Root[0][1] as EntryElement;
var two = Root[0][2] as EntryElement;
int.TryParse(one.Value, out var un);
int.TryParse(two.Value, out var deux);
SetResultElementValue($"{utility.Multiply(un, deux)}");
}
void Handle_EchoOperation()
{
var nameElement = Root[0][0] as EntryElement;
SetResultElementValue(XMUtilities.Echo(nameElement.Value));
}
void Handle_SpeakOperation()
{
SetResultElementValue(utility.Speak());
}
void Handle_SpeakGreetingOperation()
{
SetResultElementValue(utility.Speak(XMGreeting.Goodbye));
}
void Handle_HelloOperation()
{
var nameElement = Root[0][0] as EntryElement;
SetResultElementValue(utility.Hello(nameElement.Value));
}
void Handle_InvokeCallback()
{
utility.InvokeCallback("Callback invoked!");
}
void SetResultElementValue(string value)
{
NSThread.Current.BeginInvokeOnMainThread(() =>
{
if (Root[1][0] is StringElement e)
{
e.Caption = value;
TableView.ReloadData();
}
});
}
}
}

Просмотреть файл

@ -8,8 +8,8 @@
<ProjectGuid>{0CDEA6B0-A495-48B0-ADC0-A6459F730571}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>Xamarin.XMBindingLibrarySample</RootNamespace>
<AssemblyName>XamarinXMBindingLibrarySample</AssemblyName>
<RootNamespace>XMBindingLibrarySample</RootNamespace>
<AssemblyName>XMBindingLibrarySample</AssemblyName>
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
@ -75,12 +75,12 @@
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
<Reference Include="MonoTouch.Dialog-1" />
<Reference Include="XMBindingLibrary">
<HintPath>..\..\..\binding\XMBindingLibrary.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<ProjectReference Include="..\XMBindingLibrary\XMBindingLibrary.csproj">
<Project>{A62E63ED-97A6-475B-8376-912F2C027FAB}</Project>
<Name>XMBindingLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
@ -90,31 +90,22 @@
<Compile Include="ViewControllers\CustomViewController.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="ViewControllers\" />
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\icon-29.png" />
<BundleResource Include="Resources\icon-50.png" />
<BundleResource Include="Resources\icon-58.png" />
<BundleResource Include="Resources\icon-100.png" />
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\iTunesArtwork%402x.png" />
<BundleResource Include="Resources\Default-568h%402x.png" />
<BundleResource Include="Resources\Default-Landscape%402x~ipad.png" />
<BundleResource Include="Resources\Default-Landscape~ipad.png" />
<BundleResource Include="Resources\Default-Portrait%402x~ipad.png" />
<BundleResource Include="Resources\Default-Portrait~ipad.png" />
<BundleResource Include="Resources\Default.png" />
<BundleResource Include="Resources\Default%402x.png" />
<BundleResource Include="Resources\icon-57.png" />
<BundleResource Include="Resources\icon-114.png" />
<BundleResource Include="Resources\icon-144.png" />
<BundleResource Include="Resources\icon-72.png" />
</ItemGroup>
<ItemGroup>
<ITunesArtwork Include="Resources\iTunesArtwork.png" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<Import Project="BindingActions.targets" />
</Project>

4
BindingSample/src/binding/.gitignore поставляемый
Просмотреть файл

@ -1,4 +0,0 @@
*.a
*.dll
*.mdb
XMBindingLibrarySample/build/

Просмотреть файл

@ -1,4 +0,0 @@
using System;
using ObjCRuntime;
[assembly: LinkWith ("libXMBindingLibrarySampleUniversal.a", LinkTarget.Simulator | LinkTarget.Arm64 | LinkTarget.ArmV7, ForceLoad = true)]

Просмотреть файл

@ -1,30 +0,0 @@
BINDDIR=/src/binding
XBUILD=/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
PROJECT_ROOT=XMBindingLibrarySample
PROJECT=$(PROJECT_ROOT)/XMBindingLibrarySample.xcodeproj
TARGET=XMBindingLibrarySample
BTOUCH=/Developer/MonoTouch/usr/bin/btouch-native
all: XMBindingLibrary.dll
libXMBindingLibrarySample-i386.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -configuration Release clean build
-mv $(PROJECT_ROOT)/build/Release-iphonesimulator/lib$(TARGET).a $@
libXMBindingLibrarySample-armv7.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch armv7 -configuration Release clean build
-mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $@
libXMBindingLibrarySample-arm64.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch arm64 -configuration Release clean build
-mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $@
libXMBindingLibrarySampleUniversal.a: libXMBindingLibrarySample-armv7.a libXMBindingLibrarySample-i386.a libXMBindingLibrarySample-arm64.a
lipo -create -output $@ $^
XMBindingLibrary.dll: AssemblyInfo.cs XMBindingLibrarySample.cs extras.cs libXMBindingLibrarySampleUniversal.a
$(BTOUCH) -unsafe --new-style -out:$@ XMBindingLibrarySample.cs -x=AssemblyInfo.cs -x=extras.cs --link-with=libXMBindingLibrarySampleUniversal.a,libXMBindingLibrarySampleUniversal.a
clean:
-rm -f *.a *.dll

Просмотреть файл

@ -1,12 +0,0 @@
XMBindingLibrarySample Binding Project
======================================
This project contains the following items:
- AssemblyInfo.cs : This defines our output and [linking] (http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types#Linking_the_Dependencies) behavior
- extras.cs : This is where we define the partial types for our interface definitions
- XMBindingLibrarySample.cs : The API definition file which contains the interfaces which have been attributed to drive the binding.
- XMBindingLibrarySample : The Xcode project for our sample Objective-C library

Просмотреть файл

@ -1,91 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace XMBindingLibrarySample
{
using System;
using System.Drawing;
using Foundation;
using UIKit;
using ObjCRuntime;
public delegate void XMUtilityCallback (NSString message);
[BaseType (typeof (NSObject))]
interface XMUtilities
{
// Note: that we DO NOT have to bind a constructor since
// BTOUCH will automatically create the default / empty constructor for us, cool!
// [Export("init")]
// IntPtr Constructor();
// Note that this is attributed with static because it is a class method
[Static]
[Export("echo:")]
string Echo(string message);
// Methods without a parameter do not need the trailing colon (":")
// But methods with parameters do!
[Export("hello:")]
string Hello(string name);
// Again, here we have two parameters, but the method name
// and each argument are suffxed with a colon.
[Export("add:and:")]
nint Add(nint operandUn, nint operandDeux);
[Export("multiply:and:")]
nint Multiply(nint operandUn, nint operandDeux);
[Export("setCallback:")]
void SetCallback(XMUtilityCallback callback);
[Export("invokeCallback:")]
void InvokeCallback(NSString message);
}
[BaseType(typeof(UIView), Delegates = new string [] {"WeakDelegate"}, Events = new Type[] { (typeof(XMCustomViewDelegate)) })]
interface XMCustomView
{
[Export("name")]
string Name { get; [NullAllowed] set; }
[Export("delegate", ArgumentSemantic.Assign)]
[NullAllowed]
NSObject WeakDelegate { get; set; }
[Wrap("WeakDelegate")]
[NullAllowed]
XMCustomViewDelegate Delegate { get; set; }
[Export("customizeViewWithText:")]
void CustomizeViewWithText(string message);
}
[Model]
[BaseType(typeof (NSObject))]
interface XMCustomViewDelegate
{
// Notice the use of [Abstract] here since the -(void)viewWasTouched:(UIView *)view; method
// Was defined using the @required keyword in the native library.
[Abstract]
[Export ("viewWasTouched:")]
void ViewWasTouched(XMCustomView view);
}
}

Просмотреть файл

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>0D9C6A08-A740-4A6D-8FFD-95D9C1E00EC0</string>
<key>IDESourceControlProjectName</key>
<string>XMBindingLibrarySample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>0E68039F2209CEA6C5215FF8565B7310427923A7</key>
<string>https://github.com/xamarin/monotouch-samples.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>BindingSample/src/binding/XMBindingLibrarySample/XMBindingLibrarySample.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>0E68039F2209CEA6C5215FF8565B7310427923A7</key>
<string>../../../../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/xamarin/monotouch-samples.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>0E68039F2209CEA6C5215FF8565B7310427923A7</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>0E68039F2209CEA6C5215FF8565B7310427923A7</string>
<key>IDESourceControlWCCName</key>
<string>monotouch-samples</string>
</dict>
</array>
</dict>
</plist>

Просмотреть файл

@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DE6534D14C7C824007670AC"
BuildableName = "libXMBindingLibrarySample.a"
BlueprintName = "XMBindingLibrarySample"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DE6534D14C7C824007670AC"
BuildableName = "libXMBindingLibrarySample.a"
BlueprintName = "XMBindingLibrarySample"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DE6534D14C7C824007670AC"
BuildableName = "libXMBindingLibrarySample.a"
BlueprintName = "XMBindingLibrarySample"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

Просмотреть файл

@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D09B80E14C87E5F00033666"
BuildableName = "libXMBindingLibrarySampleUniversal.a"
BlueprintName = "XMBindingLibrarySampleUniversal"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D09B80E14C87E5F00033666"
BuildableName = "libXMBindingLibrarySampleUniversal.a"
BlueprintName = "XMBindingLibrarySampleUniversal"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D09B80E14C87E5F00033666"
BuildableName = "libXMBindingLibrarySampleUniversal.a"
BlueprintName = "XMBindingLibrarySampleUniversal"
ReferencedContainer = "container:XMBindingLibrarySample.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

Просмотреть файл

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>XMBindingLibrarySample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>XMBindingLibrarySampleUniversal.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>1D09B80E14C87E5F00033666</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>1DE6534D14C7C824007670AC</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

Просмотреть файл

@ -1,13 +0,0 @@
//
// XMBindingLibrarySample.h
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface XMBindingLibrarySample : NSObject
@end

Просмотреть файл

@ -1,23 +0,0 @@
//
// XMBindingLibrarySample.m
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMBindingLibrarySample.h"
@implementation XMBindingLibrarySample
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
@end

Просмотреть файл

@ -1,13 +0,0 @@
//
// XMBindingLibrarySampleUniversal.h
// XMBindingLibrarySampleUniversal
//
// Created by Anuj Bhatia on 1/19/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface XMBindingLibrarySampleUniversal : NSObject
@end

Просмотреть файл

@ -1,23 +0,0 @@
//
// XMBindingLibrarySampleUniversal.m
// XMBindingLibrarySampleUniversal
//
// Created by Anuj Bhatia on 1/19/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMBindingLibrarySampleUniversal.h"
@implementation XMBindingLibrarySampleUniversal
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
@end

Просмотреть файл

@ -1,61 +0,0 @@
//
// XMCustomView.m
// XMBindingLibrarySample
//
// Created by Anuj Bhatia on 1/18/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "XMCustomView.h"
@interface XMCustomView ()
@property (nonatomic, assign) BOOL isCustomized;
@end
@implementation XMCustomView
@synthesize name = _name, delegate = _delegate, isCustomized = _isCustomized;
-(id) init
{
if(self = [super init]) {
// do initialization hurr
self.isCustomized = false;
}
return self;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.delegate viewWasTouched:self];
}
-(void) customizeViewWithText:(NSString *)message
{
if(self.isCustomized == false && [message length] > 0) {
UITextView *txtView = [[UITextView alloc] init];
txtView.textAlignment = NSTextAlignmentCenter;
txtView.textColor = [UIColor blueColor];
txtView.frame = CGRectMake(self.frame.origin.x, ((self.frame.origin.y / 2) - 25), self.frame.size.width, 100);
// txtView.lineBreakMode = UILineBreakModeWordWrap;
// set inner shadow
txtView.layer.masksToBounds = NO;
txtView.layer.cornerRadius = 8;
txtView.layer.shadowOffset = CGSizeMake(-15, 20);
txtView.layer.shadowRadius = 5;
txtView.layer.shadowOpacity = 0.5;
txtView.layer.shadowColor = [[UIColor blackColor] CGColor];
txtView.text = message;
// [txtView sizeToFit];
[self addSubview:txtView];
}
}
@end

Просмотреть файл

@ -1,35 +0,0 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using CoreFoundation;
using CoreMedia;
using CoreMotion;
using Foundation;
using ObjCRuntime;
using CoreAnimation;
using CoreLocation;
using MapKit;
using UIKit;
using CoreGraphics;
using NewsstandKit;
using GLKit;
using OpenTK;
namespace XMBindingLibrarySample
{
public partial class XMUtilities : NSObject
{
}
public partial class XMCustomView : UIView
{
}
public partial class XMCustomViewDelegate : NSObject
{
}
}

Просмотреть файл

@ -1,11 +0,0 @@
XMBindingLibrarySample Sample Application
================
This project contains our MonoTouch sample. It has a reference to XMBindingLibrarySample.dll and makes calls to our native library written in Objective-C from C#
Example:
var utility = new XMUtilities();
var result = utility.Hello("Anuj");
Console.WriteLine(result);

Просмотреть файл

@ -1,26 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.XMBindingLibrarySample", "Xamarin.XMBindingLibrarySample\Xamarin.XMBindingLibrarySample.csproj", "{0CDEA6B0-A495-48B0-ADC0-A6459F730571}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhone.ActiveCfg = Debug|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhone.Build.0 = Debug|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhone.ActiveCfg = Release|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhone.Build.0 = Release|iPhone
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{0CDEA6B0-A495-48B0-ADC0-A6459F730571}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Xamarin.XMBindingLibrarySample\Xamarin.XMBindingLibrarySample.csproj
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,2 +0,0 @@
bin
obj

Просмотреть файл

@ -1,40 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace Xamarin.XMBindingLibrarySample
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow _Window;
RootViewController _RootViewController;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
_Window = new UIWindow(UIScreen.MainScreen.Bounds);
_RootViewController = new RootViewController();
_Window.RootViewController = _RootViewController;
_Window.MakeKeyAndVisible();
return true;
}
}
}

Просмотреть файл

@ -1,33 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace Xamarin.XMBindingLibrarySample
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
}

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 24 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 9.4 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 25 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 9.8 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 11 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 14 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 2.0 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 4.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 5.1 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 6.6 KiB

Просмотреть файл

@ -1,121 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using MonoTouch.Dialog;
using XMBindingLibrarySample;
using UIKit;
using Foundation;
using CoreGraphics;
namespace Xamarin.XMBindingLibrarySample
{
public class CustomViewController : DialogViewController
{
XMCustomView _CustomView;
public CustomViewController()
: base(new RootElement(@"XMCustomView Binding") { UnevenRows = true }, true)
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
public override void LoadView()
{
base.LoadView();
_CustomView = new XMCustomView();
// This is the custom event we bound.
// This is sometimes preferable to specifying a delegate.
_CustomView.ViewWasTouched += Handle_CustomViewViewWasTouched;
// The XMCustomViewDelegate we bound
// If we specify this it will OVERRIDE the event handler we specified
// _CustomView.Delegate = new CustomViewDelegate();
// The XMCustomView Name Property
_CustomView.Name = @"Anuj";
// The instance method uses a frame calculation.
_CustomView.Frame = new CGRect(10, 25, 200, 200);
// The instance method we bound.
_CustomView.CustomizeViewWithText(string.Format(@"Yo {0}, I hurd you like bindings! MonoTouch makes it super easy with BTOUCH. Try it out!",
_CustomView.Name ?? "Dawg"));
var section = new Section("Custom View") {
new CustomViewElement(_CustomView),
};
this.Root.Add(section);
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.NavigationItem.HidesBackButton = false;
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("Utilities", UIBarButtonItemStyle.Bordered, null);
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
}
private void Handle_CustomViewViewWasTouched (object sender, EventArgs e)
{
var customView = sender as XMCustomView;
if(customView == null) {
return;
}
// Remember, the block of this method is called on a Background Thread...
// In order to push a notification to the view we need to call within the scope of the main thread.
using(var pool = new NSAutoreleasePool()) {
pool.BeginInvokeOnMainThread(() => {
using(var alert = new UIAlertView("View Was Touched", "Our bound XMCustomView was Touched!", null, "OK, Cool!", null)) {
alert.Show();
}
});
}
}
class CustomViewDelegate : XMCustomViewDelegate
{
public override void ViewWasTouched(XMCustomView view)
{
Console.WriteLine("Hey! Our XMCustomView was touched with frame: {0}!", view.Frame);
}
}
public class CustomViewElement : UIViewElement, IElementSizing
{
public CustomViewElement(UIView customView)
: base("", customView, true)
{
}
public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
// base.Selected(dvc, tableView, path);
}
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using UIKit;
namespace Xamarin.XMBindingLibrarySample
{
public class RootViewController : UINavigationController
{
UtilitiesViewController _UtilViewController;
public RootViewController()
: base()
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
public override void LoadView()
{
base.LoadView();
_UtilViewController = new UtilitiesViewController();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.PushViewController(_UtilViewController, true);
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
}
}
}

Просмотреть файл

@ -1,144 +0,0 @@
//
// Copyright 2012 abhatia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Linq;
using MonoTouch.Dialog;
using Foundation;
using XMBindingLibrarySample;
using UIKit;
namespace Xamarin.XMBindingLibrarySample
{
public class UtilitiesViewController : DialogViewController
{
XMUtilities Utility;
public UtilitiesViewController()
: base(new RootElement("XMUtilities Binding"), true)
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
public override void LoadView()
{
base.LoadView();
Utility = new XMUtilities();
Utility.SetCallback (new XMUtilityCallback (OurCallback));
var operandSection = new Section("Operands") {
new EntryElement("Name: ", "", ""),
new EntryElement("Operand One: ", "", ""),
new EntryElement("Operand Two: ", "", ""),
};
var operationSection = new Section("Operations") {
new StringElement("Add", Handle_AddOperation),
new StringElement("Multiply", Handle_MultiplyOperation),
new StringElement("Hello", Handle_HelloOperation),
new StringElement("Invoke Callback", Handle_InvokeCallback),
};
var resultSection = new Section("Result") {
new StringElement(@"")
};
var customViewSection = new Section("More Bindings") {
new StringElement("Go to CustomView!", () => {
var c = new CustomViewController();
this.NavigationController.PushViewController(c, true);
})
};
this.Root.Add(new Section[] { operandSection, operationSection, resultSection, customViewSection });
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
}
void OurCallback (NSString message)
{
SetResultElementValue(message);
}
public void Handle_InvokeCallback ()
{
using (NSString message = new NSString ("Callback invoked!")) {
Utility.InvokeCallback (message);
}
}
public void Handle_AddOperation()
{
var one = Root[0][1] as EntryElement;
var two = Root[0][2] as EntryElement;
int un;
int deux;
if(int.TryParse(one.Value, out un) && int.TryParse(two.Value, out deux)) {
SetResultElementValue(string.Format(@"{0}", un + deux));
}
}
public void Handle_MultiplyOperation()
{
var one = Root[0][1] as EntryElement;
var two = Root[0][2] as EntryElement;
int un;
int deux;
if(int.TryParse(one.Value, out un) && int.TryParse(two.Value, out deux)) {
SetResultElementValue(string.Format(@"{0}", un * deux));
}
}
public void Handle_HelloOperation()
{
var nameElement = Root[0][0] as EntryElement;
SetResultElementValue(Utility.Hello(nameElement.Value));
}
public void SetResultElementValue(string @value)
{
using(var pool = new NSAutoreleasePool()) {
pool.BeginInvokeOnMainThread(() => {
var e = Root[2][0] as StringElement;
if(e != null) {
e.Caption = value;
this.TableView.ReloadData();
}
});
}
}
}
}