Skip to content

Commit 4a3088f

Browse files
committed
Implemented the iOS side and some adjustments to Android.
1 parent 5e24dde commit 4a3088f

File tree

11 files changed

+179
-139
lines changed

11 files changed

+179
-139
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,41 @@ jobs:
4848
name: androidBuild
4949
path: example/export/android/bin/app/build/outputs/apk/debug
5050
if-no-files-found: warn
51+
iOS:
52+
runs-on: macos-15
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@main
56+
57+
- name: Setup Haxe
58+
uses: krdlab/setup-haxe@master
59+
with:
60+
haxe-version: 4.3.6
61+
62+
- name: Install Haxe Libraries
63+
run: |
64+
haxelib install lime --quiet --never --skip-dependencies
65+
haxelib dev extension-iarcore .
66+
67+
- name: Setup hxcpp Library
68+
run: haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp.git --quiet --never --skip-dependencies && haxelib run lime rebuild hxcpp
69+
70+
- name: List Installed Haxe Libraries
71+
run: haxelib list
72+
73+
- name: Build
74+
run: cd example && haxelib run lime build ios -nosign -debug
75+
76+
- name: Create IPA
77+
run: |
78+
cd example/export/ios/build/Debug-iphoneos
79+
mkdir Payload
80+
mv *.app Payload
81+
zip -r Sample.ipa Payload
82+
83+
- name: Upload Artifact
84+
uses: actions/upload-artifact@main
85+
with:
86+
name: iOSBuild
87+
path: example/export/ios/build/Debug-iphoneos/Sample.ipa
88+
if-no-files-found: warn

example/source/Main.hx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
package;
22

3-
import extension.iarcore.IAR;
3+
#if android
4+
import extension.iarcore.android.IARAndroid;
5+
#elseif ios
6+
import extension.iarcore.ios.IARIOS;
7+
#end
48

59
class Main extends lime.app.Application
610
{
711
public function new():Void
812
{
913
super();
1014

11-
IAR.onLog.add(function(message:String):Void
15+
#if android
16+
IARAndroid.onLog.add(function(message:String):Void
1217
{
1318
trace('IAR Failed with "$message"');
1419
});
15-
IAR.onReviewCompleted.add(function(success:Bool):Void
20+
IARAndroid.onReviewCompleted.add(function(success:Bool):Void
1621
{
1722
trace('IAR Review Completed with "${success ? 'Success' : 'Failure'}"');
1823
});
19-
IAR.onReviewError.add(function(message:String):Void
24+
IARAndroid.onReviewError.add(function(message:String):Void
2025
{
2126
trace('IAR Review Failed with "$message"');
2227
});
28+
#end
2329
}
2430

2531
public override function onWindowCreate():Void
2632
{
27-
IAR.init();
28-
IAR.requestAndLaunchReviewFlow();
33+
#if android
34+
IARAndroid.init();
35+
IARAndroid.requestAndLaunchReviewFlow();
36+
#elseif ios
37+
IARIOS.requestReview();
38+
#end
2939
}
3040

3141
public override function render(context:lime.graphics.RenderContext):Void

extension/iarcore/IAR.hx

Lines changed: 0 additions & 5 deletions
This file was deleted.

extension/iarcore/android/IARAndroid.hx

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package extension.iarcore.android;
22

33
#if android
4-
import extension.iarcore.android.util.JNICache;
54
import lime.app.Event;
5+
import lime.system.JNI;
66

77
/**
88
* A class for managing in-app reviews on Android using Google Play's In-App Review API.
@@ -18,42 +18,70 @@ class IARAndroid
1818
/** Event triggered when a review flow fails. */
1919
public static final onReviewError:Event<String->Void> = new Event<String->Void>();
2020

21+
/** Cache for storing created static JNI method references. */
22+
@:noCompletion
23+
private static var staticMethodsCache:Map<String, Dynamic> = [];
24+
2125
/**
22-
* Initializes the review managers.
26+
* Initializes the review manager by calling the corresponding Java method and registering the callback object.
2327
*/
2428
public static function init():Void
2529
{
26-
final initJNI:Null<Dynamic> = JNICache.createStaticMethod('org/haxe/extension/IARCore', 'init', '(Lorg/haxe/lime/HaxeObject;)V');
30+
final initJNI:Null<Dynamic> = createJNIStaticMethod('org/haxe/extension/IARCore', 'init', '(Lorg/haxe/lime/HaxeObject;)V');
2731

2832
if (initJNI != null)
2933
initJNI(new IARAndroidCallbackObject());
3034
}
3135

3236
/**
33-
* Requests and launches the review flow.
37+
* Requests the in-app review information and launches the review dialog when ready.
3438
*/
3539
public static function requestAndLaunchReviewFlow():Void
3640
{
37-
final requestAndLaunchReviewFlowJNI:Null<Dynamic> = JNICache.createStaticMethod('org/haxe/extension/IARCore','requestAndLaunchReviewFlow', '()V');
41+
final requestAndLaunchReviewFlowJNI:Null<Dynamic> = createJNIStaticMethod('org/haxe/extension/IARCore', 'requestAndLaunchReviewFlow', '()V');
3842

3943
if (requestAndLaunchReviewFlowJNI != null)
4044
requestAndLaunchReviewFlowJNI();
4145
}
4246

4347
/**
44-
* Requests and launches the fake review flow.
48+
* Requests and launches a fake review flow (typically used for testing).
4549
*/
4650
public static function requestAndLaunchFakeReviewFlow():Void
4751
{
48-
final requestAndLaunchFakeReviewFlowJNI:Null<Dynamic> = JNICache.createStaticMethod('org/haxe/extension/IARCore', 'requestAndLaunchFakeReviewFlow', '()V');
52+
final requestAndLaunchFakeReviewFlowJNI:Null<Dynamic> = createJNIStaticMethod('org/haxe/extension/IARCore', 'requestAndLaunchFakeReviewFlow', '()V');
4953

5054
if (requestAndLaunchFakeReviewFlowJNI != null)
5155
requestAndLaunchFakeReviewFlowJNI();
5256
}
57+
58+
/**
59+
* Retrieves or creates a cached static method reference.
60+
* @param className The name of the Java class containing the method.
61+
* @param methodName The name of the method to call.
62+
* @param signature The JNI method signature string (e.g., "()V", "(Ljava/lang/String;)V").
63+
* @param cache Whether to cache the result (default true).
64+
* @return A dynamic reference to the static method, or null if it couldn't be created.
65+
*/
66+
@:noCompletion
67+
private static function createJNIStaticMethod(className:String, methodName:String, signature:String, cache:Bool = true):Null<Dynamic>
68+
{
69+
@:privateAccess
70+
className = JNI.transformClassName(className);
71+
72+
final key:String = '$className::$methodName::$signature';
73+
74+
if (cache && !staticMethodsCache.exists(key))
75+
staticMethodsCache.set(key, JNI.createStaticMethod(className, methodName, signature));
76+
else if (!cache)
77+
return JNI.createStaticMethod(className, methodName, signature);
78+
79+
return staticMethodsCache.get(key);
80+
}
5381
}
5482

5583
@:noCompletion
56-
private class IARAndroidCallbackObject #if (lime >= "8.0.0") implements lime.system.JNI.JNISafety #end
84+
private class IARAndroidCallbackObject #if (lime >= "8.0.0") implements JNISafety #end
5785
{
5886
public function new():Void {}
5987

extension/iarcore/android/util/JNICache.hx

Lines changed: 0 additions & 119 deletions
This file was deleted.

extension/iarcore/ios/IARIOS.hx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package extension.iarcore.ios;
2+
3+
#if ios
4+
/**
5+
* A class for managing in-app reviews on iOS Devices using StoreKit.
6+
*/
7+
@:buildXml('<include name="${haxelib:extension-iarcore}/project/iarcore-ios/Build.xml" />')
8+
@:headerInclude('iar_core.hpp')
9+
class IARIOS
10+
{
11+
/**
12+
* Requests an in-app review from the user, if appropriate for the current platform and context.
13+
*/
14+
public static function requestReview():Void
15+
{
16+
requestReviewIAR();
17+
}
18+
19+
@:native('IAR_RequestReview')
20+
@:noCompletion
21+
extern private static function requestReviewIAR():Void;
22+
}
23+
#end

haxelib.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"license": "MIT",
55
"tags": [
66
"android",
7+
"ios",
78
"java",
9+
"objcpp",
810
"haxe",
911
"lime",
1012
"iar"
1113
],
12-
"description": "A Haxe/Lime extension that implements In-App Reviews (IAR) functionality for Android devices.",
14+
"description": "A Haxe/Lime extension that implements In-App Reviews (IAR) functionality for Android and iOS devices.",
1315
"version": "1.0.1",
1416
"releasenote": "Fixes to the README.",
1517
"contributors": [

include.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99

1010
<config:android extension="org.haxe.extension.IARCore" />
1111
</section>
12+
13+
<dependency name="StoreKit.framework" if="ios" />
1214
</extension>

project/iarcore-ios/Build.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xml>
3+
<pragma once="true" />
4+
5+
<files id="haxe">
6+
<compilerflag value="-I${haxelib:extension-iarcore}/project/iarcore-ios/include" />
7+
</files>
8+
9+
<files id="__main__">
10+
<compilerflag value="-I${haxelib:extension-iarcore}/project/iarcore-ios/include" />
11+
</files>
12+
13+
<files id="iarcore">
14+
<compilerflag value="-I${haxelib:extension-iarcore}/project/iarcore-ios/include" />
15+
16+
<file name="${haxelib:extension-iarcore}/project/iarcore-ios/src/iar_core.mm" />
17+
</files>
18+
19+
<target id="haxe">
20+
<vflag name="-framework" value="StoreKit" />
21+
22+
<files id="iarcore" />
23+
</target>
24+
</xml>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
/**
4+
* Requests an in-app review from the user, if appropriate for the current platform and context.
5+
*/
6+
void IAR_RequestReview(void);

0 commit comments

Comments
 (0)