Implementing Applovin Ads with Swift & SpriteKit - ios

I would like some help with integrating interstitial ads from Applovin using Swift. Currently, I have managed to successfully integrate the SDK and initialize it using ALSdk.initializeSdk(). I have a folder in my project directory called Applovin which contains: headers folder (with all the .h files inside) and libApplovinSdk.a.
I have a BridgingHeader.h file in which I am importing the relevant frameworks
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>
#import <AVFoundation/AVFoundation.h>
#import<CoreTelephony/CTCallCenter.h>
#import<CoreTelephony/CTCall.h>
#import<CoreTelephony/CTCarrier.h>
#import<CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CoreMedia/CoreMedia.h>
#import <MediaPlayer/MediaPlayer.h>
#import <SystemConfiguration/SystemConfiguration.h>
// Core SDK
#import "ALErrorCodes.h"
#import "ALSdk.h"
#import "ALSdkSettings.h"
#import "ALTargetingData.h"
#import "ALPostbackService.h"
#import "ALPostbackDelegate.h"
// Standard Ads
#import "ALAd.h"
#import "ALAdDisplayDelegate.h"
#import "ALAdLoadDelegate.h"
#import "ALAdRewardDelegate.h"
#import "ALAdService.h"
#import "ALAdSize.h"
#import "ALAdType.h"
#import "ALAdUpdateDelegate.h"
#import "ALAdVideoPlaybackDelegate.h"
#import "ALAdView.h"
#import "ALIncentivizedInterstitialAd.h"
#import "ALInterstitialAd.h"
// Native Ads
#import "ALNativeAd.h"
#import "ALNativeAdService.h"
#import "ALNativeAdPrecacheDelegate.h"
#import "ALNativeAdLoadDelegate.h"
In my AppDelegate i have the following methods, what do I need to put inside these methods?
func adService(adService: ALAdService, didLoadAd ad: ALAd) {
}
func adService(adService: ALAdService, didFailToLoadAdWithError code: Int32) {
}
I am attempting to show ads using the following code but ALInterstitialAd.isReadyForDisplay() is always false, I am probably missing something very obvious but I am not sure what it is, any help is appreciated, thanks!
if ALInterstitialAd.isReadyForDisplay() == true {
ALInterstitialAd.show()
} else {
println("No Applovin Ad available to show")
}

You likely need to enable "Test Mode" for your app in the AppLovin dashboard in order to force test ads to serve for your area. Please send any questions to support#applovin.com for further assistance.

Related

Use of undeclared identifier 'FIRApp'

After import the Firebase.h file i wrote "[FIRApp configure]" on "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions". While running on the simulator it is showing "Use of undeclared identifier 'FIRApp'". But if select "Generic iOS device" option for build, no error is coming. Build and Archive working as properly. But on local simulator issue is coming.I have to run the app on Simulator first for crash communications with Firebase server. Please give me solution.enter
In AppDelegate.m file, you should import firebase like #import <Firebase.h> before #ifdef FB_SONARKIT_ENABLED line.
As I understand, You probably get success on dev build because FlipperKit libraries are used for debugging and this #ifdef FB_SONARKIT_ENABLED if condition is satisfied. When you try to archive it will not be imported and the variables will be undeclared because #import <Firebase.h> remains in that if condition.
FIRApp is moved (or initially was) to FirebaseCore framework. So.
#import <FirebaseCore/FirebaseCore.h>.
As stated in this github comment:
What work for me
Just add
#import <Firebase.h> to the AppDelegate.h as well
Source:
I have a same problem but I haven't FB_SONARKIT_ENABLED
#import <React/RCTAppSetupUtils.h>
#if RCT_NEW_ARCH_ENABLED
#import <Firebase.h>
#import <FirebaseCore/FirebaseCore.h>
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>
static NSString *const kRNConcurrentRoot = #"concurrentRoot";
#interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
#end
#endif
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
RCTAppSetupPrepareApp(application);
enter image description here
In the react native firebase docs (see here: https://rnfirebase.io/) it says put the #import <Firebase.h> at the top of the document. You imported #import <Firebase.h> below #if RCT_NEW_ARCH_ENABLED, so you basically import firebase module if the RCT_NEW_ARCH_ENABLED condition is true.
you should do :
#import <Firebase.h>
#import <React/RCTAppSetupUtils.h>
#if RCT_NEW_ARCH_ENABLED
#import <FirebaseCore/FirebaseCore.h>
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>

React-Native: Error trying to get in touch with native module in the tutorial

Having issue with defining a native module from the tutorial in https://facebook.github.io/react-native/docs/native-modules-ios.html.
#import "CalendarManager.h"
#import <React/RCTLog.h>
#implementation CalendarManager
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent: (NSString *)name location: (NSString *)location)
{
}
#end
It give me the compile error in RCT_EXPORT_METHOD saying
"Expected ')'"
.
and
'Type specifier missing, defaults to int' (later also appeared under
RCT_EXPORT_MODULE)
You need to insert #import <React/RCTBridgeModule.h> in CalendarManager.h either.
Like this
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
NS_ASSUME_NONNULL_BEGIN
#interface CalendarManager : NSObject<RCTBridgeModule>
#end
NS_ASSUME_NONNULL_END

Do all react-native '.h' modules have to be prepended with 'React/'?

Setup:
react-native v0.41.2
react-native-cli v2.0.1
xcode v8.2.1
node v6.9.5
I started using RN v0.41.2 and found that v0.40 introduced a namespace breaking change stating that all react imports should be prepended with React/.
But the documentation shows otherwise.
So, is doing this the only thing that I have to do:
// RNLib.h
#import "RCTBridgeModule.h"
#interface RNLib : NSObject <RCTBridgeModule>
#end
to
// RNLib.h
#import <React/RCTBridgeModule.h>
#interface RNLib : NSObject <RCTBridgeModule>
#end
Or do I have to do it for my imports as well:
// RNLib.m
#import "RNLib.h"
#implementation RNLib
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(helloWorld:(NSString *)world)
{
return [NSString stringWithFormat:#"hello %#", world];
}
#end
to
// RNLib.m
#import <React/RNLib.h>
#implementation RNLib
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(helloWorld:(NSString *)world)
{
return [NSString stringWithFormat:#"hello %#", world];
}
#end
I'm currently unable to create a library and link it correctly (I've tried multiple things).
// somthing.m
#import "something.h"
This above line refers to something.h file which is present in same directory of the implementation file.
Only Modules from the React should be prepended with "React/RCTWhatever.h".
This has effective change in Header Search Paths of Xcode when you are linking the Native Libraries.
Thanks

Importing Foundation.h, but using :NSObject

I am a bit confused what the ": SuperClass" is for. Let say I have a model class called MyClass, which is subclass of NSObject. I write in its interface that the class is subclass of NSObject, but actually I almost never import only NSObject header file. What I import is whole Foundation.h precompiled header file.
#import <Foundation/Foundation.h>
#interface MyClass : NSObject
Is it only convention to write that I subclass from NSObject instead of Foundation, or is there any other meaning behind?
Foundation.h imports all the classes present in foundation framework and hence NSObject.h.
If you just want to import NSObject.h the you should use
#import <Foundation/NSObject.h>
Below is the Foundation.h file source
/* Foundation.h
Copyright (c) 1994-2013, Apple Inc. All rights reserved.
*/
#include <CoreFoundation/CoreFoundation.h>
#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSByteOrder.h>
#import <Foundation/NSCalendar.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSDateFormatter.h>
#import <Foundation/NSDecimal.h>
#import <Foundation/NSDecimalNumber.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSError.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileHandle.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSFormatter.h>
#import <Foundation/NSHashTable.h>
#import <Foundation/NSHTTPCookie.h>
#import <Foundation/NSHTTPCookieStorage.h>
#import <Foundation/NSIndexPath.h>
#import <Foundation/NSIndexSet.h>
#import <Foundation/NSInvocation.h>
#import <Foundation/NSJSONSerialization.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSKeyValueObserving.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSLocale.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSMapTable.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSNotificationQueue.h>
#import <Foundation/NSNull.h>
#import <Foundation/NSNumberFormatter.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSOperation.h>
#import <Foundation/NSOrderedSet.h>
#import <Foundation/NSOrthography.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSPointerArray.h>
#import <Foundation/NSPointerFunctions.h>
#import <Foundation/NSPort.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSPropertyList.h>
#import <Foundation/NSProxy.h>
#import <Foundation/NSRange.h>
#import <Foundation/NSRegularExpression.h>
#import <Foundation/NSRunLoop.h>
#import <Foundation/NSScanner.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSSortDescriptor.h>
#import <Foundation/NSStream.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTextCheckingResult.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSTimer.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSURLAuthenticationChallenge.h>
#import <Foundation/NSURLCache.h>
#import <Foundation/NSURLConnection.h>
#import <Foundation/NSURLCredential.h>
#import <Foundation/NSURLCredentialStorage.h>
#import <Foundation/NSURLError.h>
#import <Foundation/NSURLProtectionSpace.h>
#import <Foundation/NSURLProtocol.h>
#import <Foundation/NSURLRequest.h>
#import <Foundation/NSURLResponse.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSValueTransformer.h>
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSZone.h>
#import <Foundation/FoundationErrors.h>
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
#import <Foundation/NSAttributedString.h>
#import <Foundation/NSByteCountFormatter.h>
#import <Foundation/NSCache.h>
#import <Foundation/NSComparisonPredicate.h>
#import <Foundation/NSCompoundPredicate.h>
#import <Foundation/NSExpression.h>
#import <Foundation/NSFileCoordinator.h>
#import <Foundation/NSFilePresenter.h>
#import <Foundation/NSFileVersion.h>
#import <Foundation/NSFileWrapper.h>
#import <Foundation/NSLinguisticTagger.h>
#import <Foundation/NSMetadata.h>
#import <Foundation/NSMetadataAttributes.h>
#import <Foundation/NSNetServices.h>
#import <Foundation/NSPredicate.h>
#import <Foundation/NSProgress.h>
#import <Foundation/NSUbiquitousKeyValueStore.h>
#import <Foundation/NSUndoManager.h>
#import <Foundation/NSURLSession.h>
#import <Foundation/NSUUID.h>
#endif
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || TARGET_OS_WIN32
#import <Foundation/NSArchiver.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSConnection.h>
#import <Foundation/NSDistantObject.h>
#import <Foundation/NSDistributedNotificationCenter.h>
#import <Foundation/NSGeometry.h>
#import <Foundation/NSPortCoder.h>
#import <Foundation/NSPortMessage.h>
#import <Foundation/NSPortNameServer.h>
#import <Foundation/NSProtocolChecker.h>
#import <Foundation/NSTask.h>
#import <Foundation/NSXMLDTD.h>
#import <Foundation/NSXMLDTDNode.h>
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSXMLElement.h>
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLNodeOptions.h>
#import <Foundation/NSURLDownload.h>
#import <Foundation/NSURLHandle.h>
#endif
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
#import <Foundation/NSAffineTransform.h>
#import <Foundation/NSAppleEventDescriptor.h>
#import <Foundation/NSAppleEventManager.h>
#import <Foundation/NSAppleScript.h>
#import <Foundation/NSClassDescription.h>
#import <Foundation/NSDistributedLock.h>
#import <Foundation/NSGarbageCollector.h>
#import <Foundation/NSHFSFileTypes.h>
#import <Foundation/NSHost.h>
#import <Foundation/NSObjectScripting.h>
#import <Foundation/NSScriptClassDescription.h>
#import <Foundation/NSScriptCoercionHandler.h>
#import <Foundation/NSScriptCommand.h>
#import <Foundation/NSScriptCommandDescription.h>
#import <Foundation/NSScriptExecutionContext.h>
#import <Foundation/NSScriptKeyValueCoding.h>
#import <Foundation/NSScriptObjectSpecifiers.h>
#import <Foundation/NSScriptStandardSuiteCommands.h>
#import <Foundation/NSScriptSuiteRegistry.h>
#import <Foundation/NSScriptWhoseTests.h>
#import <Foundation/NSSpellServer.h>
#import <Foundation/NSUserNotification.h>
#import <Foundation/NSUserScriptTask.h>
#import <Foundation/NSXPCConnection.h>
#endif
About Is it only convention to write..
See you're not going to use only NSObject.h to implement your class, you may need NSArray/NSDictionary/NSDate/etc. etc. Thus instead of importing all these classes we usually import the Foundation.h
Take a look at Foundation.h - it's importing all core objects for you.
You could use:
#import <Foundation/NSObject.h>
If you know you will never use other objects - but it's more convenient to just import all Foundation classes, since you will be using them pretty often :)
And you should always subclass NSObject since there is no "Foundation" class.
NSObject provides a basic interface to the runtime system and the ability to behave as Objective-C objects.

HttpClient setReachabilityStatusChangedBlock declares no interface

Trying to use AFNetworkings ReachabilityStatusChanged but getting
"No visible #interface for HTTPCLIENT declares the selector setReachabilityStatusChangeBlock"
But HttpClient has that function. Anyone know why this is happening?
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:#"http://stat-api.herokuapp.com/"]];
[client setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
NSLog(#"%d", status);
}];
/// UPDATE ///////////
Here is my .pch file
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "NSDate+Helper.h"
#import "NSEntityDescription+RKAdditions.h"
#import "UIAlertView+MKBlockAdditions.h"
#import "UIActionSheet+MKBlockAdditions.h"
#import "MKBlockAdditions.h"
#import "NSObject+MKBlockAdditions.h"
#import "NSString+Extra.h"
#import "UIView+Additions.h"
#import "ObjectiveSugar.h"
#import "NSNotificationCenter+UniqueNotif.h"
#import "STUIColor+Custom.h"
#import "NSObject+STNSObjectAdditions.h"
#import "UIView+Gradientcy.h"
#import "NSString+USStateMap.h"
#import "STUITextField.h"
#import "UIImage+UIImageCrop.h"
#import "UIBorderLabel.h"
#import <SystemConfiguration/SystemConfiguration.h>
#endif
Move
#import <SystemConfiguration/SystemConfiguration.h>
right after this line:
#ifdef __OBJC__
Are you sure you're using a version of AFNetworking that have this method?
Also, check this warning from the docs:
Warning: This method requires the SystemConfiguration framework.
Add it in the active target’s “Link Binary With Library” build phase, and add #import <SystemConfiguration/SystemConfiguration.h> to the header prefix of the project (Prefix.pch).

Resources