Now I'm using google ads . I followed the step from here(convert OC to C#).And I have add a new adUnitID .It built without error.However.My bannerView didn't display on my test device.Any advice? I know from other forum that google admob will be blocked in some countries, is that true?
in Appdelegate.cs
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
Window.RootViewController = new XttcViewController();
Window.MakeKeyAndVisible();
MobileAds.Configure("xxx");
return true;
}
in ViewController.cs
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.bannerView = new BannerView(new CGRect(0,100,320,50));
View.AddSubview(this.bannerView);
this.bannerView.AdUnitID = "xxx";
this.bannerView.RootViewController = this;
this.bannerView.LoadRequest(Request.GetDefaultRequest());
}
If you have recently created an AD unit ID(in 24 hours), it may take some time and several AD requests to build up AD resources. Because of this, you may not immediately see the actual presentation. You can use the test unitID. Please note that the test AD runs through the same channels as the actual AD. If the test AD returns, your application is communicating correctly with the network.
The test ID for bannerview in iOS is "ca-app-pub-3940256099942544/2934735716".
If your issue persists even if you use the test ID.You can check for more specific causes from the google support
Related
My app has many types of ads (banner, transitions, rewarded video etc) in it. I have developed my app with Android Studio.
I test them all ads with test IDs as Google says.
After being confident that ads are working, I have changed test IDs to real IDs.
When I run the app on a phone physiacally connected to my PC, the ads are not shown. Some documents say that "real unitIDs never work unless the app is downloaded from Play Store source". That means I have to upload my app to Play Console each time to test real IDs.
But, loading the app to Play Console for test puprpose is not applicable because;
It takes long time to come alive (review period)
If I even accept to wait for that review period, when the app become alive, the users may download the bugy app because it is for test purpose and not a confident version.
You may say, if the app works with test IDs then it will work with real IDs bu it is not true.
Because my app works well with test IDs. When I switch to real IDs, banners keeps working but rewarded video ads doesn't.
My admob account and all adUnits seems ok. This is not an issue about my adMob account.
So the question is that, is there a way to test my app with admob's real unitIDs without uploading the app to Play Console and download it from Play Store?
Thanks,
Yes, you can test your Live Ids.
put this block of code in your splash activity (first activity), run your app you will get something like this in log, test_id replace this in your code...
I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("test_id"))
List<String> testDeviceIds = Arrays.asList("test_id");
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
ref:
https://developers.google.com/admob/android/test-ads
for Rewareded interstial ads try this code:
make your class... implements OnUserEarnedRewardListener.
if anything goes wrong you will get error message in onAdFailedToLoad, using loadAdError.getMessage();
private RewardedInterstitialAd rewardedInterstitialAd;
#Override
public void onUserEarnedReward(#NonNull RewardItem rewardItem) {
Log.i(TAG, "onUserEarnedReward");
// TODO: Reward the user!
}
public void loadRewardedAd() {
// Use the test ad unit ID to load an ad.
RewardedInterstitialAd.load(MainActivity.this, getString(R.string.rewarded_interstitial_id),
new AdRequest.Builder().build(), new RewardedInterstitialAdLoadCallback() {
#Override
public void onAdLoaded(RewardedInterstitialAd ad) {
rewardedInterstitialAd = ad;
rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
/** Called when the ad failed to show full screen content. */
#Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
Log.i(TAG, "onAdFailedToShowFullScreenContent");
}
/** Called when ad showed the full screen content. */
#Override
public void onAdShowedFullScreenContent() {
Log.i(TAG, "onAdShowedFullScreenContent");
}
/** Called when full screen content is dismissed. */
#Override
public void onAdDismissedFullScreenContent() {
Log.i(TAG, "onAdDismissedFullScreenContent");
}
});
}
#Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
Log.e(TAG, "onAdFailedToLoad");
}
});
}
I created Azure Notification Hub and added the server key from Firebase to the section "GCM/FCM" in notification hub. After which, I used the shared access key and notification hub name to create the installation (following the Azure documentation). Here's the code that I used:
[FunctionName("TestFunction")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
HttpRequest req, ILogger log)
{
var deviceUpdate = new DeviceInstallation()
{
installationId = "<myInstallationid>",
pushChannel = "<DeviceTokenGeneratedByFirebase>",
platform = "fcm",
tags = new string[] {"notificationhubtag1"},
};
var responseMessage = new HttpResponseMessage();
try
{
responseMessage = await Put(deviceUpdate);
}
catch
{
log.LogInformation("exception occured");
}
return new OkObjectResult(responseMessage);
}
// Custom API
public static async Task<HttpResponseMessage> Put(DeviceInstallation deviceUpdate)
{
NotificationHubClient hub = new NotificationHubClient(fullAccessConnString, hubName);
Installation installation = new Installation();
installation.InstallationId = deviceUpdate.installationId;
installation.PushChannel = deviceUpdate.pushChannel;
installation.Tags = deviceUpdate.tags;
switch (deviceUpdate.platform)
{
case "mpns":
installation.Platform = NotificationPlatform.Mpns;
break;
case "wns":
installation.Platform = NotificationPlatform.Wns;
break;
case "apns":
installation.Platform = NotificationPlatform.Apns;
break;
case "fcm":
installation.Platform = NotificationPlatform.Fcm;
break;
default:
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
await hub.CreateOrUpdateInstallationAsync(installation);
return new HttpResponseMessage(HttpStatusCode.OK);
}
public class DeviceInstallation
{
public string installationId { get; set; }
public string platform { get; set; }
public string pushChannel { get; set; }
public string[] tags { get; set; }
}
When I run this code, I get a successful message back. The Azure portal itself does not show much information about the no. of devices registered or active devices information in the Azure notification hub. However, I was able to confirm that the installation exists by making a GET request to the installation API directly through this call:
https://<myNotificationHubNameSpace>.servicebus.windows.net/<myHubName>/installations/<myInstallationId>/?api-version=2015-01
This call returned me a 200 OK with the installation I created from the earlier step. The response looked like this:
{"installationId":"<myInstallationId>","pushChannel":"<DeviceTokenGeneratedByFireBase>","pushChannelExpired":false,"platform":"gcm","expirationTime":"9999-12-31T23:59:59.9999999Z","tags":["notificationhubtag1"]}
So, I went to the Azure Notification Hub and sent a test message from the "Test Send" tab and used the tag "notificationhubtag1" in the SendTo tags field. I got back the successful message that said "The Notification was successfully sent to the Push Notification System" and also got the Registration number.
However, I don't see any notifications being sent to the app itself. How can I debug more information about this specific message being pushed. Where did it get pushed?
Is there any way to find more information on the pushed messages, installed devices etc on the notification hub itself? I found an old post about checking logs which said to switch to standard tier instead of free Tier for more information. I have made the switch to standard tier but I don't see any difference in the way overview or activity logs is displayed to me between Free or Standard Tier.
Notification Hubs acts as a bit of a proxy. So the message you saw in the Portal when performing the test send means it did successfully hand off the notification to FCM to be sent and got a success response back from FCM. This also means the device token was valid.
At that point there is no additional data Notification Hubs can provide since it is no longer in the system.
When we've seen issues like this in the past it tends to imply there is something not quite right in the app configuration itself. Likely there is some logic missing for handling the notification intent.
From the code snippet above, it looks like you are creating the installation from some server side piece and not from the application. My assumption is this means you are still working on integrating the Android SDK for Notification Hubs, since the normal flow is to have devices register themselves with the Hub.
We document the full end-to-end steps here: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started
I would mostly recommend looking closely at the various code changes necessary on the Android side. Manifest updates and code changes. If you continue to have issues receiving notifications, please feel free to open a support request in the Portal and we can dig deeper into what's going on.
I am following this guide https://github.com/Azure-Samples/active-directory-xamarin-native-v2/tree/master/1-Basic
and have this code in my app.xaml.cs
public App()
{
PCA = PublicClientApplicationBuilder.Create(applicationClientId)
.WithTenantId("tenantidhere")
.WithRedirectUri($"msal{applicationClientId}://auth")
.WithIosKeychainSecurityGroup("com.microsoft.adalcache") // focussing on android first so ignore this one
.Build();
//...
}
I get the message that there is something wrong with the return url... and the continue button does not seem to work. I don't know if the issues are related or sepearate.
Here are my azure settings in the azure AD:
I felt that I had to switch back to the 'old experience' because the guides/tutorials etc. does not seem to reflect the current Azure UI.
You will have updated the value of DataScheme on MsalActivity.cs and AndroidManifest.xml with the correspondent clientId of your application.
I cant' get InterstitialAd to work in my UWP app when running on the Windows Phone Emulator (Note that I haven't tried it yet on actual real phone)
It works as expected when I run my UWP app in the Simulator or Local Machine as a Windows Store app.
Any ideas?
Thanks.
UPDATE - 1
Here is the code I use to display the InterstitialAd. In my MainPage.xaml.cs I have the following code:
public sealed partial class MainPage : Page
{
private InterstitialAd interstitialAd;
public MainPage()
{
this.InitializeComponent();
// Instantiate the interstitial video ad
interstitialAd = new InterstitialAd();
// Attach event handlers
interstitialAd.ErrorOccurred += OnAdError;
interstitialAd.AdReady += OnAdReady;
interstitialAd.Cancelled += OnAdCancelled;
interstitialAd.Completed += OnAdCompleted;
}
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad is ready to play.
private void OnAdReady(object sender, object e)
{
// The ad is ready to show; show it.
interstitialAd.Show();
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad is cancelled.
private void OnAdCancelled(object sender, object e)
{
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad has completed playback.
private void OnAdCompleted(object sender, object e)
{
}
// This is an error handler for the interstitial ad.
private void OnAdError(object sender, AdErrorEventArgs e)
{
}
I've literarily taken this code from their UWP Store sample except that instead of launching this from a button, I'm launching it when my page is loaded:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// Request an ad. When the ad is ready to show,
// the AdReady event will fire.
// The application id and ad unit id are passed in here.
// The application id and ad unit id can be obtained from Dev
// Center.
// See "Monetize with Ads" at https://msdn.microsoft.com/
// en-us/library/windows/apps/mt170658.aspx
#if DEBUG
interstitialAd.RequestAd(AdType.Video,
"d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#else
interstitialAd.RequestAd(AdType.Video,
"d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#endif
}
I've left both ApplicationId and UnitAdId as the test values for the time being as I haven't released it yet, well, not with ads anyway.
Thanks
UPDATE - 2:
I've added some debugging logs in the various events and this is what I get:
Page_Loaded: 00:00:00.0001590
Page_Loaded - RequestAd: 00:00:00.0091840
OnAdReady - Elasped Time: 00:01:04.6923865
OnAdError: NetworkConnectionFailure : Media timeout occurred
during playback. - Elasped
Time: 00:00:08.1955928
It takes over 1 minute for the OnAdReady to be triggered which is really odd and then I get an OnAdError 8 seconds later so from these logs you would assume that there is a network problem but my data is being loaded correctly which is all pulled from a web service, so there is definitely a connection. Also my AdMediator displays Ads as expected (well, kind of! That's another story!).
I will try to transfer it directly to my phone tomorrow and see if it makes any differences and I plug in my laptop to an Ethernet port instead of using the wireless but my wireless is pretty decent, so I'm not sure why I'm getting network connectivity errors.
The above code is correct and does actually work with UWP on Windows Phone but it doesn't work great in the emulator as:
it intermittently generates network connectivity errors when they are none.
it can take over a minute to display the advert but it eventually will.
I've just uploaded my app to the store and downloaded it to my phone and it works as expected. It displays the advert immediately or within a couple of seconds or so.
I would recommend you do not waste too much time trying it via the phone emulator as it appears to be the main problem. Implement your code and then test it directly on your device or download it from the store assuming you haven't released your app yet.
UPDATE:
I just thought I'd update my answer as I was just reading about the do's and dont's with interstitial adverts from UI and User Experience Guidelines and the way I'm actually doing it, is one of points in the "avoid" list.
It recommends that you fetch the advert 30-60 seconds ahead of time and you don't display it when the app starts, which is what I'm doing, so I guess I will change the logic in that regards.
I have developed a windows phone 8 application. Now I want to display vserv ads to my application.
I have added the sdk to my application and also applied code to show ads:
public MainPage()
{
InitializeComponent();
VservAdControl VMB = VservAdControl.Instance;
VMB.DisplayAd(zoneID, LayoutRoot);
VMB.VservAdClosed += new EventHandler(VACCallback_OnVservAdClosing);
VMB.VservAdNoFill += new EventHandler(VACCallback_OnVservAdNoFill);
}
void VACCallback_OnVservAdClosing(object sender, EventArgs e)
{
MessageBox.Show("Ad close by user.");
}
void VACCallback_OnVservAdNoFill(object sender, EventArgs e)
{
if (adGrid != null)
adGrid.Visibility = Visibility.Collapsed;
}
But after closing the ad the application page goes blank, all content, application bar automatically goes blank. After using back arrow that quits my application, i try to relaunch my application but application stuck at the splash screen on the emulator.
Wrap ad control inside a grid. Ad control could have manipulated the grid
I encountered the same issue and they have updated their SDK several times. If you provide the stacktrace they will provide you a fix.
Apart from what you have seen, there are other issues with the SDK. I integrated it few weeks back. So issues could have been resolved after that.
Memory leak. Click the ad or navigate back and forth - you will see the memory ever growing. This is because of events not being detached (withing SDK). I was consistently able to see my app crash in 512 MB emulator when banner ad is loaded (after 4 - 5 times). They could have used weak listeners. You might need to tweak a lot to overcome this issue (In multi page app)
RequestAdCallback throws null pointer exception sometimes crashing
the app. When people use app, they will navigate fast - forcing the
webbrowser to unload. All callbacks should be null pointer exception
free. Make sure that you handle unhandled exception globally otherwise app will not pass certification
It reads WMAppManifest.xml as text not as XML. So I had App element commented in first line before the actual one. It picked title from commented XML element
Application bar is manipulated in many events in the SDK. So you have to make sure that app bar is built dynamically. Test all navigation paths.
SDK assumes user will click the left arrow button which fires ad closing event. Try pressing phone back button instead. The app bar still disappears
SDK documentation requests app to demand ID_CAP_REMOVABLE_STORAGE capability. I don't see a reason to request this capability but I didn't add this
I have emailed them all these details. May be their latest SDK could have resolved these issues. But please do thorough testing after integration.
Add a function to load applicationbar using code
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = false;
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/sms.png", UriKind.Relative);
button1.Text = "sms";
ApplicationBar.Buttons.Add(button1);
}
and then in VACCallback_OnVservAdClosing event handler call the function
BuildLocalizedApplicationBar()
Please check the following link,
where to add application id and adUnitiD while integrating vserv ads sdk to windows phone 8 application, which is related to your question.