I'm trying to implement Mopub into my Flutter project but I have some issues related to mopub_flutter package.
MopubAdManager class contains the IDs of Mopub stuff.
This is my initState:
void initState() {
try {
MoPub.init(MopubAdManager().publisherId, testMode: true).then((_) => {
loadRewardedAd(),
});
} catch (e) {
print('exception: ${e.toString()}');
}
super.initState();
This is the loadRewaredAd function
void loadRewardedAd() {
videoAd = MoPubRewardedVideoAd(MopubAdManager().rewardedAd, (result, args) {
setState(() {
var rewardedResult = '${result.toString()}____$args';
});
print('$result');
if (result == RewardedVideoAdResult.GRANT_REWARD) {
print('Grant reward: $args');
}
}, reloadOnClosed: true);
This is how I call the function inside a button with onPressed
RaisedButton(
child: Text('Show Video'),
onPressed: () async {
videoAd.load();
var result = await videoAd.isReady();
print('Is Ready $result');
if (result) {
videoAd.show();
}
},
),
Before touching the button, Mopub prints that line in console:
I/MoPub (30148): [com.mopub.network.TrackingRequest$1][onResponse] SDK Log - Successfully hit tracking endpoint: https://ads.mopub.com/m/open
After touching the Show Video button that appears in console:
V/AudioManager(30148): querySoundEffectsEnabled...
I/MoPub (30148): [com.mopub.mobileads.MoPubRewardedVideoManager][fetchAd] SDK Log - Loading rewarded ad request for ad unit 40825097a53247c5a91f9775d3f54298 with URL https://ads.mopub.com/m/ad?v=6&id=40825097a53247c5a91f9775d3f54298&nv=5.15.0&dn=HUAWEI%2CPOT-LX1%2CPOT-LX1&bundle=com.example.anket&z=%2B0300&o=p&cw=1080&ch=2259&w=1080&h=2340&sc=3.0&ct=2&av=1.0.0&abt=%7B%22tapjoy%22%3A%7B%22token%22%3A%221%22%7D%7D&ifa=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&tas=mp_tmpl_tas&mid=mp_tmpl_mopub_id&gdpr_applies=0&force_gdpr_applies=0¤t_consent_status=unknown&vv=4&vver=1.3.4-Mopub&mr=1
I/MoPub (30148): [com.mopub.network.AdLoader][fetchAd] Ad requesting from AdServer: https://ads.mopub.com/m/ad
I/MoPub (30148): {"vv":"4","nv":"5.15.0","mid":"e458ffd9-db59-4753-9878-c923a99ef3fc","dn":"HUAWEI,POT-LX1,POT-LX1","sc":"3.0","current_consent_status":"unknown","vver":"1.3.4-Mopub","id":"40825097a53247c5a91f9775d3f54298","bundle":"com.example.anket","gdpr_applies":"0","ch":"2259","ifa":"fe6b229f-fa21-4367-ac77-f8437ef7ebb6","mr":"1","tas":"authorized","h":"2340","force_gdpr_applies":"0","dnt":"0","o":"p","ct":"2","abt":"{\"tapjoy\":{\"token\":\"1\"}}","cw":"1080","av":"1.0.0","v":"6","w":"1080","z":"+0300"}
I/flutter (30148): Is Ready false
I/MoPub (30148): [com.mopub.network.MultiAdResponse][parseSingleAdResponse] Ad server responded with:
I/MoPub (30148): {"content":"","metadata":{"x-adtype":"clear","x-backfill":"clear","x-refreshtime":60}}
I/MoPub (30148): [com.mopub.network.AdLoader$1][onErrorResponse] Ad server responded with:
I/MoPub (30148): No ads found for ad unit.
I/flutter (30148): Flutter mopub rewarded method error
I/flutter (30148): RewardedVideoAdResult.ERROR
Other Ad types such as banner, interstitial shows the same error.
I have created the ad units and copied the Ids to the MopubAdManager class but yet no ads appear in the app. I have tested the test Ids they work perfectly.
Did I skip something?
Related
My issue is the login with the email and password function works fine on android but on iOS, the promise is never returned ( nor failed ) when correct credentials are provided but it fails if I provide incorrect credentials. The login works on iOS with live reload simulating on an iOS device, but when installed with test-flight or via xCode promise is never returned nor rejected.
How can I debug it further or know what the underlying issue is?
onSubmit: async (values) => {
try {
const auth = getAuth(firebaseApp);
auth.setPersistence(browserSessionPersistence);
// Never called on IOS
auth.onAuthStateChanged(() => {
console.log('I am here', auth.currentUser);
if (auth.currentUser) {
updateIsAuthenticated(true);
}
});
const userCred = await signInWithEmailAndPassword(auth, values.email, values.password);
//Never runs
console.log('After Success', userCred);
} catch (error) {
// Runs when provided with false credentials
setError('Error: Authentication failed');
console.error('An error Occurred');
} finally {
console.log('Running Finally');
}
},
});
I have a flutter app setup to run google ads using the google_mobile_ads package. All packages are the most recent. I configured it for iOS & Android and the test ads are loading on iOS as expected but not on Android 11.0. This is only an issue on Android 11.0 - API R. When run on Android 9.0 - API 28 the test ads load.
My configuration:
AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-MY_APP_ID"/>
initState()
setState(() {
_banner = BannerAd(
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
size: AdSize.fullBanner,
request: AdRequest(),
listener: bannerListener,
)..load();
});
where bannerListener is:
final BannerAdListener bannerListener = BannerAdListener(
onAdLoaded: (Ad ad) => print('Ad loaded.'),
onAdFailedToLoad: (Ad ad, LoadAdError error) {
ad.dispose();
print('Ad failed to load: $error');
},
onAdOpened: (Ad ad) => print('Ad opened.'),
onAdClosed: (Ad ad) => print('Ad closed.'),
);
When I run on Android I get the following error:
AdWidget requires Ad.load to be called before AdWidget is inserted into the tree
If I change the code up to split the ..load() to a different line I then get this error:
I/Ads (11598): Ad failed to load : 0
I/flutter (11598): Ad failed to load: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Internal error., responseInfo: ResponseInfo(responseId: null, mediationAdapterClassName: , adapterResponses: []))
I'm showing the banner with this code:
if (_banner == null)
SizedBox(height: 20)
else
Container(
height: 50,
child: AdWidget(ad: _banner!),
)
What am I doing wrong that the test Ads won't load on Android but iOS has no issue?
I am trying to ad facebook_audience_network banner ads in my multiple screens.
I am using following method to create banner ad in each flutter app screen. The issue i am facing is whichever screen(screens with banner ad implementation code) i open for the first time it loads ad successfully.
But, when i go to another screen then it doesn't load ads anyway. I have also implemented logic that ad requests are made throughout the app after 30 seconds. Still i am not able to load ads on other screens once loaded in first screen.
createBannerAd() {
_currentAd = Container(
alignment: Alignment(0.5, 1),
child: FacebookBannerAd(
placementId: IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047,
bannerSize: BannerSize.STANDARD,
listener: (result, value) {
switch (result) {
case BannerAdResult.ERROR:
_adShown = false;
print("Error: $value");
break;
case BannerAdResult.LOADED:
print("Loaded: $value");
break;
case BannerAdResult.CLICKED:
print("Clicked: $value");
break;
case BannerAdResult.LOGGING_IMPRESSION:
print("Logging Impression: $value");
break;
}
},
),
);
setState(() {});
}
Error log :
D/EgretLoader(25084): EgretLoader(Context context)
D/EgretLoader(25084): The context is not activity
W/cr_AwContents(25084): Application attempted to call on a destroyed WebView
W/cr_AwContents(25084): java.lang.Throwable
W/cr_AwContents(25084): at org.chromium.android_webview.AwContents.a(PG:126)
W/cr_AwContents(25084): at TA0.loadingStateChanged(PG:2)
W/cr_AwContents(25084): at android.os.MessageQueue.nativePollOnce(Native Method)
W/cr_AwContents(25084): at android.os.MessageQueue.next(MessageQueue.java:325)
W/cr_AwContents(25084): at android.os.Looper.loop(Looper.java:148)
W/cr_AwContents(25084): at android.app.ActivityThread.main(ActivityThread.java:6634)
W/cr_AwContents(25084): at java.lang.reflect.Method.invoke(Native Method)
W/cr_AwContents(25084): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/cr_AwContents(25084): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
I/flutter (25084): Error: {error_message: No Fill, error_code: 1001, invalidated: false, placement_id: IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047}
I am not getting what is the issue with this code. I have followed the documentation steps.
So can anyone suggest me a solution for this? I think this is a major issue.
Thanks.
My Flutter application flow works like this:
User logins
1-If login successfully, server returns a token
2-Set token to local storage in webview
3-Open Webview fullscreen to a specific URL
I am using this Webview plugin. The sample code shows that it supports local storage (it has a withLocalStorage option) but does not show how to use it.
I am aware of this question1 question2
f I correctly set the local storage, the Webview would show account page; otherwise a login page (
That's Not What Happened)
Instade am getting this error
I/chromium(13409): [INFO:CONSOLE(1)] "Uncaught SyntaxError: Invalid or unexpected token", source: (1)
My code:
void webwiew(token) {
flutterWebViewPlugin
.launch(
"URLExpml",
withLocalStorage: true,
withJavascript: true,
)
.whenComplete(() {
final res = flutterWebViewPlugin.evalJavascript("(function() { try { window.localStorage.setItem('token', $token); } catch (err) { return err; } })();");
print("Eval result webview : ${res.toString()}");
});
}
From https://github.com/fluttercommunity/flutter_webview_plugin/pull/51#issuecomment-399468804
You can wait until the first page loading is completed and then accessing LocalStorage with evalJavascript
To achieve this you can use onStateChanged.listen and check state.type == WebViewState.finishLoad
StreamSubscription<WebViewStateChanged> _onStateChanged;
_onStateChanged = flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged state) {
if (mounted) {
if (state.type == WebViewState.finishLoad) {
flutterWebviewPlugin.evalJavascript(
"window.localStorage.setItem('LOCAL_STORAGE','SOMETOKEN');" +
"document.getElementById('showLocalStorageBtn').click();"
);
}
}
});
I am launching a flutter app (App 1) from another flutter app (App 2) on Android and it works perfectly. However, I keep getting the same error on IOS. It does not recognize the package name.
I have tried with multiple apps but is the same result, it currently just recognizes the calendar package.
pubspec.yaml file flutter_appavailability
main.dart App 2
import 'package:flutter_appavailability/flutter_appavailability.dart';
//Future void method
if (Platform.isIOS) {
_installedApps = [
{"app_name": "example", "package_name": "com.flutter.example"},
];
print(await AppAvailability.checkAvailability("com.flutter.example")); //ERROR
//Widget build
return Container {
child : Row(
...
GestureDetector(
...
onTap: () {
Scaffold.of(context).hideCurrentSnackBar();
AppAvailability.launchApp(installedApps[0].["package_name"])
.then((_) {
print("App ${installedApps[0]["app_name"]} launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"App ${installedApps[0]["app_name"]} not found!")));
print(err);
});
...
),
}
info.plist App 1
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
project.pbxproj App 1
PRODUCT_BUNDLE_IDENTIFIER = com.flutter.example;
Output App 2
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(, App not found com.flutter.example, null)
#0 AppAvailability.checkAvailability (package:flutter_appavailability/flutter_appavailability.dart:40:9)