0

I'm trying to create à binding library from this project https://github.com/Eclair/CircleProgressBar.

I use sharpie to generate the ApiDefinition.cs and the .a files.

> sharpie pod init ios CircleProgressBar
> sharpie bind

I copied the .a file in my project and put the generated c# code in my ApiDefinition.cs file. However the generated code does not compile.

I think that the problem is that, these lines

typedef NSString*(^StringGenerationBlock)(CGFloat progress);
typedef NSAttributedString*(^AttributedStringGenerationBlock)(CGFloat progress);

Are converted to these

delegate string StringGenerationBlock (nfloat arg0);
delegate NSAttributedString AttributedStringGenerationBlock (nfloat arg0);

But the compiler suggests to replace string with IntPtr, and even if I do that and even if the project is compiled, my application crashes if I try to instantiate a CircleProgressBar

4

1 回答 1

0

1st:

Change the string that is causing the error to an NSString (and not an IntPtr):

// typedef NSString * (^StringGenerationBlock)(CGFloat);
delegate NSString StringGenerationBlock (nfloat arg0);

Now the binding project in your solution should compile without errors.

2nd:

Debug/Test on an actual device

By default sharpie pod XXXXX is not going to create a static library that will work in the iOS Simulator and it also does not allow for creating of fat libraries, you would have to do that manually.

Create a iphonesimulator based static library if desired:

For that you need to manually build the xcode project with the sdk set to iphonesimulator.

i.e.

xcodebuild -project Pods.xcodeproj -target Pods -sdk iphonesimulator -configuration Debug clean build

You can use that output with the original .a to create a fat lib.

Really quick example:

if (circleProgressBar == null) {
    circleProgressBar = new CircleProgressBar ();
    circleProgressBar.Frame = new CoreGraphics.CGRect (this.View.Frame.Width / 4, this.View.Frame.Width / 4, this.View.Frame.Width / 2, this.View.Frame.Width / 2);
    circleProgressBar.ProgressBarWidth = 33.0f;
    circleProgressBar.BackgroundColor = UIColor.Clear;
    circleProgressBar.ProgressBarProgressColor = UIColor.Green;
    circleProgressBar.ProgressBarTrackColor = UIColor.Red;
    circleProgressBar.StartAngle = 0.0f;
    circleProgressBar.SetProgress (0.0f, false);
    this.Add (circleProgressBar);
} else {
    circleProgressBar.SetProgress (circleProgressBar.Progress + 0.1f, true);
}

Results in:

enter image description here

于 2016-01-19T18:13:02.877 回答