Skip to content

Commit

Permalink
Merge pull request #15 from AGulev/unity-sdk-3-5-0
Browse files Browse the repository at this point in the history
Unity sdk 3 5 0
  • Loading branch information
AGulev authored Oct 5, 2020
2 parents b4e6866 + a65d7c1 commit 8d2a22c
Show file tree
Hide file tree
Showing 20 changed files with 684 additions and 330 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ unityads.TYPE_DID_ERROR
unityads.TYPE_DID_FINISH
unityads.TYPE_BANNER
unityads.TYPE_BANNER_ERROR
unityads.TYPE_INITIALIZED
unityads.TYPE_INIT_ERROR
```
##### unityads.TYPE_IS_READY
```lua
Expand Down Expand Up @@ -250,6 +252,25 @@ local function defunityads_callback(self, msg_type, message)
end
end
```

#### Initialization error types
```lua
--possible message.error for unityads.TYPE_INIT_ERROR:
unityads.INIT_ERROR_INTERNAL_ERROR -- initialization failed due to environment or internal services
unityads.INIT_ERROR_INVALID_ARGUMENT -- initialization failed due to invalid argument(e.g. game ID)
unityads.INIT_ERROR_AD_BLOCKER_DETECTED -- initialization failed due to url being blocked
```
```lua
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_INIT_ERROR then
if message.error == unityads.INIT_ERROR_INTERNAL_ERROR then
...
elseif message.error == unityads.INIT_ERROR_INVALID_ARGUMENT then
...
end
end
```

#### Finish states
[Original doc about finish states](https://github.com/Unity-Technologies/unity-ads-ios/wiki/sdk_ios_api_finishstates)
```lua
Expand Down
16 changes: 16 additions & 0 deletions defunityads/api/DefUnityAds.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
- name: TYPE_BANNER
type: number

- name: TYPE_INITIALIZED
type: number

- name: TYPE_INIT_ERROR
type: number


#*****************************************************************************************************

Expand Down Expand Up @@ -176,6 +182,16 @@
- name: ERROR_INTERNAL
type: number

#*****************************************************************************************************

- name: INIT_ERROR_INTERNAL_ERROR
type: number

- name: INIT_ERROR_INVALID_ARGUMENT
type: number

- name: INIT_ERROR_AD_BLOCKER_DETECTED
type: number

#*****************************************************************************************************

Expand Down
Binary file modified defunityads/lib/android/classes.jar
Binary file not shown.
57 changes: 52 additions & 5 deletions defunityads/lib/ios/UnityAds.framework/Headers/UnityAds.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#import "UADSBannerView.h"
#import "UADSBannerViewDelegate.h"
#import "UADSBannerError.h"
#import "UnityAdsInitializationError.h"
#import "UnityAdsInitializationDelegate.h"
#import "UnityAdsLoadDelegate.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -61,6 +64,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (void)initialize:(NSString *)gameId;

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
*
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param initializationDelegate delegate for UnityAdsInitialization
*/
+ (void)initialize:(NSString *)gameId
initializationDelegate:(nullable id<UnityAdsInitializationDelegate>)initializationDelegate;

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
*
Expand All @@ -73,14 +85,25 @@ NS_ASSUME_NONNULL_BEGIN
testMode:(BOOL)testMode __attribute__((deprecated("Please migrate to using initialize without a delegate and add the delegate with the addDelegate method")));

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
*
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param testMode Set this flag to `YES` to indicate test mode and show only test ads.
*/
* Initializes UnityAds. UnityAds should be initialized when app starts.
*
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param testMode Set this flag to `YES` to indicate test mode and show only test ads.
*/
+ (void)initialize:(NSString *)gameId
testMode:(BOOL)testMode;

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
*
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param testMode Set this flag to `YES` to indicate test mode and show only test ads.
* @param initializationDelegate delegate for UnityAdsInitialization
*/
+ (void)initialize:(NSString *)gameId
testMode:(BOOL)testMode
initializationDelegate:(nullable id<UnityAdsInitializationDelegate>)initializationDelegate;

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
Expand All @@ -107,13 +130,37 @@ NS_ASSUME_NONNULL_BEGIN
testMode:(BOOL)testMode
enablePerPlacementLoad:(BOOL)enablePerPlacementLoad;

/**
* Initializes UnityAds. UnityAds should be initialized when app starts.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param testMode Set this flag to `YES` to indicate test mode and show only test ads.
* @param enablePerPlacementLoad Set this flag to `YES` to disable automatic placement caching. When this is enabled, developer must call `load` on placements before calling show
* @param initializationDelegate delegate for UnityAdsInitialization
*/
+ (void)initialize:(NSString *)gameId
testMode:(BOOL)testMode
enablePerPlacementLoad:(BOOL)enablePerPlacementLoad
initializationDelegate:(nullable id<UnityAdsInitializationDelegate>)initializationDelegate;

/**
* Load a placement to make it available to show. Ads generally take a few seconds to finish loading before they can be shown.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param placementId The placement ID, as defined in Unity Ads admin tools.
*/
+ (void)load:(NSString *)placementId;

/**
* Load a placement to make it available to show. Ads generally take a few seconds to finish loading before they can be shown.
* Note: The `load` API is in closed beta and available upon invite only. If you would like to be considered for the beta, please contact Unity Ads Support.
*
* @param placementId The placement ID, as defined in Unity Ads admin tools.
* @param loadDelegate The load delegate.
*/
+ (void)load:(NSString *)placementId loadDelegate:(nullable id<UnityAdsLoadDelegate>)loadDelegate;

/**
* Show an ad using the defaul placement.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#import "UnityAdsInitializationError.h"

NS_ASSUME_NONNULL_BEGIN

/**
* The `UnityAdsInitializationDelegate` defines the methods which will notify UnityAds
* has either successfully initialized or failed with error category and error message
*/

@protocol UnityAdsInitializationDelegate <NSObject>
/**
* Called when `UnityAds` is successfully initialized
*/
- (void)initializationComplete;
/**
* Called when `UnityAds` is failed in initialization.
* @param error
* if `kUnityInitializationErrorInternalError`, initialization failed due to environment or internal services
* if `kUnityInitializationErrorInvalidArgument`, initialization failed due to invalid argument(e.g. game ID)
* if `kUnityInitializationErrorAdBlockerDetected`, initialization failed due to url being blocked
* @param message A human readable error message
*/
- (void)initializationFailed:(UnityAdsInitializationError)error withMessage:(NSString *)message;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* An enumeration for the error category of initialization errors
*/
typedef NS_ENUM(NSInteger, UnityAdsInitializationError)
{
/**
* Error related to environment or internal services.
*/
kUnityInitializationErrorInternalError,

/**
* Error related to invalid arguments
*/
kUnityInitializationErrorInvalidArgument,

/**
* Error related to url being blocked
*/
kUnityInitializationErrorAdBlockerDetected

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
NS_ASSUME_NONNULL_BEGIN

/**
* The `UnityAdsLoadDelegate` protocol defines the required methods for receiving messages from UnityAds.load() method.
*/
@protocol UnityAdsLoadDelegate <NSObject>
/**
* Callback triggered when a load request has successfully filled the specified placementId with an ad that is ready to show.
*
* @param placementId The ID of the placement as defined in Unity Ads admin tools.
*/
- (void)unityAdsAdLoaded:(NSString *)placementId;
/**
* Callback triggered when load request has failed to load an ad for a requested placement.
*
* @param placementId The ID of the placement as defined in Unity Ads admin tools.
*/
- (void)unityAdsAdFailedToLoad:(NSString *)placementId;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ typedef NS_ENUM(NSInteger, UnityAdsPlacementState) {
/**
* A state that indicates that the placement is ready to show an ad. The `show:` selector can be called.
*/
kUnityAdsPlacementStateReady,
kUnityAdsPlacementStateReady,
/**
* A state that indicates that no state is information is available.
* @warning This state can that UnityAds is not initialized or that the placement is not correctly configured in the Unity Ads admin tool.
*/
kUnityAdsPlacementStateNotAvailable,
kUnityAdsPlacementStateNotAvailable,
/**
* A state that indicates that the placement is currently disabled. The placement can be enabled in the Unity Ads admin tools.
*/
kUnityAdsPlacementStateDisabled,
kUnityAdsPlacementStateDisabled,
/**
* A state that indicates that the placement is not currently ready, but will be in the future.
* @note This state most likely indicates that the ad content is currently caching.
*/
kUnityAdsPlacementStateWaiting,
kUnityAdsPlacementStateWaiting,
/**
* A state that indicates that the placement is properly configured, but there are currently no ads available for the placement.
*/
kUnityAdsPlacementStateNoFill
kUnityAdsPlacementStateNoFill
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "UnityAdsInitializationDelegate.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -20,11 +21,14 @@ typedef NS_ENUM(NSInteger, UnityServicesError) {
* @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor.
* @param delegate delegate for UnityAdsDelegate callbacks
* @param testMode Set this flag to `YES` to indicate test mode and show only test ads.
* @param usePerPlacementLoad If true, disables automatic requests, and allows the load() function to request placements instead
* @param initializationDelegate Delegate for UnityAdsInitializationDelegate callbacks
*/
+ (void)initialize:(NSString *)gameId
delegate:(nullable id<UnityServicesDelegate>)delegate
testMode:(BOOL)testMode
usePerPlacementLoad:(BOOL)usePerPlacementLoad;
usePerPlacementLoad:(BOOL)usePerPlacementLoad
initializationDelegate:(nullable id<UnityAdsInitializationDelegate>)initializationDelegate;

/**
* Get the current debug status of `UnityAds`.
Expand Down Expand Up @@ -61,6 +65,8 @@ typedef NS_ENUM(NSInteger, UnityServicesError) {
*/
+ (BOOL)isInitialized;

+ (NSString *)createExpectedParametersString:(NSString *)fieldName current:(NSString *)current received:(NSString *)received;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ framework module UnityAds {
header "UnityServices.h"
header "UnityAnalytics.h"
header "UANAApiAnalytics.h"
header "UnityAdsInitializationDelegate.h"
header "UnityAdsInitializationError.h"
header "UnityAdsLoadDelegate.h"

header "USRVUnityPurchasing.h"
header "USRVUnityPurchasingDelegate.h"
Expand Down
Binary file modified defunityads/lib/ios/UnityAds.framework/UnityAds
Binary file not shown.
6 changes: 6 additions & 0 deletions defunityads/src/DefUnityAds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ static void LuaInit(lua_State* L)
SETCONSTANT(TYPE_DID_FINISH)
SETCONSTANT(TYPE_BANNER)
SETCONSTANT(TYPE_BANNER_ERROR)
SETCONSTANT(TYPE_INITIALIZED)
SETCONSTANT(TYPE_INIT_ERROR)

SETCONSTANT(FINISH_STATE_ERROR)
SETCONSTANT(FINISH_STATE_COMPLETED)
Expand Down Expand Up @@ -196,6 +198,10 @@ static void LuaInit(lua_State* L)
SETCONSTANT(BANNER_ERROR_WEBVIEW)
SETCONSTANT(BANNER_ERROR_NOFILL)

SETCONSTANT(INIT_ERROR_INTERNAL_ERROR)
SETCONSTANT(INIT_ERROR_INVALID_ARGUMENT)
SETCONSTANT(INIT_ERROR_AD_BLOCKER_DETECTED)

#undef SETCONSTANT
lua_pop(L, 1);
assert(top == lua_gettop(L));
Expand Down
Loading

0 comments on commit 8d2a22c

Please sign in to comment.