Skip to content

Commit

Permalink
Merge pull request #120 from Poing-Studios/ios-background-thread-call…
Browse files Browse the repository at this point in the history
…-function

feat: added set_ios_app_pause_on_background #99
  • Loading branch information
gumaciel authored Dec 17, 2023
2 parents f5648b6 + 722dbf6 commit f690cef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions addons/admob/sample/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func _ready() -> void:
request_configuration.convert_to_dictionary()
MobileAds.set_request_configuration(request_configuration)
MobileAds.initialize(on_initialization_complete_listener)


func _on_initialization_complete(initialization_status : InitializationStatus) -> void:
print("MobileAds initialization complete")
Expand Down
25 changes: 23 additions & 2 deletions addons/admob/sample/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://0esyp38ds6yg"]
[gd_scene load_steps=19 format=3 uid="uid://0esyp38ds6yg"]

[ext_resource type="Script" path="res://addons/admob/sample/Main.gd" id="1_xm28w"]
[ext_resource type="Texture2D" uid="uid://to8hnfn5fmrl" path="res://addons/admob/assets/icon-76.png" id="2_b280g"]
Expand All @@ -11,6 +11,8 @@
[ext_resource type="PackedScene" uid="uid://iy12nk8vefwy" path="res://addons/admob/sample/Rewarded.tscn" id="8_atpxc"]
[ext_resource type="PackedScene" uid="uid://cpxd2i7v6t6b6" path="res://addons/admob/sample/RewardedInterstitial.tscn" id="9_iwe72"]
[ext_resource type="PackedScene" uid="uid://bnptawvmfxhhu" path="res://addons/admob/sample/Ump.tscn" id="10_7toto"]
[ext_resource type="AudioStream" uid="uid://f3f176vu6pfo" path="res://addons/admob/assets/music.ogg" id="12_3yie5"]
[ext_resource type="Script" path="res://addons/admob/sample/MobileAds.gd" id="12_tjkhy"]

[sub_resource type="Theme" id="Theme_1p2mi"]
default_font = ExtResource("3_acnhc")
Expand Down Expand Up @@ -133,8 +135,10 @@ text = "AdMob Plugin - Poing Studios"
[node name="Body" type="TabContainer" parent="Background/Content/Main"]
layout_mode = 2
current_tab = 5
[node name="Banner" parent="Background/Content/Main/Body" instance=ExtResource("6_xt5vc")]
visible = false
layout_mode = 2
[node name="Interstitial" parent="Background/Content/Main/Body" instance=ExtResource("7_5rtn7")]
Expand All @@ -154,13 +158,28 @@ visible = false
layout_mode = 2
[node name="MobileAds" type="VBoxContainer" parent="Background/Content/Main/Body"]
visible = false
layout_mode = 2
script = ExtResource("12_tjkhy")
[node name="GetInitializationStatus" type="Button" parent="Background/Content/Main/Body/MobileAds"]
layout_mode = 2
text = "GetInitializationStatus"
[node name="SetiOSAppPauseOnBackgroundButton" type="CheckButton" parent="Background/Content/Main/Body/MobileAds"]
layout_mode = 2
text = "Set iOS App Pause On Background"
alignment = 1
[node name="SetMuteMusic" type="CheckButton" parent="Background/Content/Main/Body/MobileAds"]
layout_mode = 2
text = "Mute Music"
alignment = 1
[node name="Music" type="AudioStreamPlayer" parent="Background/Content/Main/Body/MobileAds"]
stream = ExtResource("12_3yie5")
volume_db = -10.0
autoplay = true
[node name="Output" type="RichTextLabel" parent="Background/Content"]
visible = false
layout_mode = 2
Expand All @@ -174,3 +193,5 @@ visible_ratio = 0.480769
[connection signal="pressed" from="Background/Content/DonateButtons/HBoxContainer/Ko-fi" to="Background/Content/DonateButtons/HBoxContainer/Ko-fi" method="_on_pressed"]
[connection signal="pressed" from="Background/Content/DonateButtons2/HBoxContainer/PayPal" to="Background/Content/DonateButtons2/HBoxContainer/PayPal" method="_on_pressed"]
[connection signal="pressed" from="Background/Content/Main/Body/MobileAds/GetInitializationStatus" to="." method="_on_get_initialization_status_pressed"]
[connection signal="pressed" from="Background/Content/Main/Body/MobileAds/SetiOSAppPauseOnBackgroundButton" to="Background/Content/Main/Body/MobileAds" method="_on_set_ios_app_pause_on_background_button_pressed"]
[connection signal="pressed" from="Background/Content/Main/Body/MobileAds/SetMuteMusic" to="Background/Content/Main/Body/MobileAds" method="_on_mute_music_pressed"]
13 changes: 13 additions & 0 deletions addons/admob/sample/MobileAds.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends VBoxContainer

@onready var set_ios_app_pause_on_background_button := $SetiOSAppPauseOnBackgroundButton
@onready var set_mute_music := $SetMuteMusic
@onready var music := $Music

func _on_set_ios_app_pause_on_background_button_pressed() -> void:
var enabled : bool = set_ios_app_pause_on_background_button.button_pressed
MobileAds.set_ios_app_pause_on_background(enabled)

func _on_mute_music_pressed() -> void:
music.playing = not set_mute_music.button_pressed

6 changes: 5 additions & 1 deletion addons/admob/src/api/MobileAds.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static func initialize(on_initialization_complete_listener : OnInitializationCom
on_initialization_complete_listener.on_initialization_complete.call(initialization_status)
)

static func set_request_configuration(request_configuration : RequestConfiguration):
static func set_request_configuration(request_configuration : RequestConfiguration) -> void:
if _plugin:
#test_device_ids needs to be passed separarely because Dictionary can't serialize Arrays
_plugin.set_request_configuration(request_configuration.convert_to_dictionary(), request_configuration.test_device_ids)
Expand All @@ -45,3 +45,7 @@ static func get_initialization_status() -> InitializationStatus:
var initialization_status_dictionary : Dictionary = _plugin.get_initialization_status()
return InitializationStatus.create(initialization_status_dictionary)
return null

static func set_ios_app_pause_on_background(pause : bool) -> void:
if _plugin and OS.get_name() == "iOS":
_plugin.set_ios_app_pause_on_background(pause)

0 comments on commit f690cef

Please sign in to comment.