Skip to content

upgrade to 3.7.2 and update api definitions #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 1542274521559.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Funky.GoogleIMA.iOS.3.7.3.nupkg
Binary file not shown.
29 changes: 29 additions & 0 deletions Funky.GoogleIMA.iOS.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata minClientVersion="">
<id>Funky.GoogleIMA.iOS</id>
<version>3.7.3</version>
<title>Funky - Goolge IMA</title>
<authors>Wenfengcheng, NAXAM</authors>
<owners>Wenfengcheng, NAXAM CO.,LTD</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://opensource.org/licenses/MIT</licenseUrl>
<projectUrl>https://github.com/Wenfengcheng/googleima-ios-binding</projectUrl>
<description>Xamarin.iOS Binding Library - GoogleIMA</description>
<summary>Xamarin Binding Library - Goolge IMA</summary>
<releaseNotes>GoogleIMA 3.7.3</releaseNotes>
<copyright></copyright>
<language>en</language>
<tags>Xamarin.iOS, Xamarin, google-ima, ima, interactive-media-ads, vast</tags>
<dependencies>
<group targetFramework="Xamarin.iOS1.0" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework="Xamarin.iOS1.0" />
<frameworkAssembly assemblyName="Xamarin.iOS" targetFramework="Xamarin.iOS1.0" />
</frameworkAssemblies>
</metadata>
<files>
<file src="/Users/highview/Desktop/PersionGit/googleima-ios-binding/Naxam.GoogleIMA.iOS/bin/Release/Naxam.GoogleIMA.iOS.dll" target="lib/xamarinios10/Naxam.GoogleIMA.iOS.dll" />
</files>
</package>
Binary file removed Naxam.GoogleIMA.iOS.3.5.2.nupkg
Binary file not shown.
208 changes: 126 additions & 82 deletions Naxam.GoogleIMA.iOS/ApiDefinition.cs

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion Naxam.GoogleIMA.iOS/Naxam.GoogleIMA.iOS.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,6 +10,19 @@
<RootNamespace>Naxam.GoogleIMA.iOS</RootNamespace>
<AssemblyName>Naxam.GoogleIMA.iOS</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<PackOnBuild>true</PackOnBuild>
<PackageId>Funky.GoogleIMA.iOS</PackageId>
<PackageVersion>3.7.3</PackageVersion>
<Authors>Wenfengcheng, NAXAM</Authors>
<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<Owners>Wenfengcheng, NAXAM CO.,LTD</Owners>
<PackageProjectUrl>https://github.com/Wenfengcheng/googleima-ios-binding</PackageProjectUrl>
<PackageReleaseNotes>GoogleIMA 3.7.3</PackageReleaseNotes>
<Summary>Xamarin Binding Library - Goolge IMA</Summary>
<PackageTags>Xamarin.iOS, Xamarin, google-ima, ima, interactive-media-ads, vast</PackageTags>
<Title>Funky - Goolge IMA</Title>
<Description>Xamarin.iOS Binding Library - GoogleIMA</Description>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -43,8 +57,12 @@
<ItemGroup>
<NativeReference Include="..\framework\GoogleInteractiveMediaAds.framework">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
</ItemGroup>
<ItemGroup>
<BundleResource Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets')" />
</Project>
4 changes: 4 additions & 0 deletions Naxam.GoogleIMA.iOS/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.Build.Packaging" version="0.2.0" targetFramework="xamarinios10" developmentDependency="true" />
</packages>
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Google IMA - Xamarin iOS Binding Library

This is the binding library for Goole IMA library on iOS.

[Android Binding Library](https://github.com/martijn00/ExoPlayerXamarin)

Plz follow the official guide from Google [here](https://developers.google.com/interactive-media-ads/);

```
Install-Package Naxam.GoogleIMA.iOS
```
#### Setup
* Available on NuGet: https://www.nuget.org/packages/Funky.GoogleIMA.iOS/ [![NuGet](https://img.shields.io/nuget/v/Funky.GoogleIMA.iOS.svg?label=NuGet)](https://www.nuget.org/packages/Funky.GoogleIMA.iOS/)
* Install in your iOS client projects.

#### ScreenShot
<a href="https://github.com/Wenfengcheng/googleima-ios-binding/blob/master/1542274521559.gif">
<img src="https://github.com/Wenfengcheng/googleima-ios-binding/blob/master/1542274521559.gif"></a>
4 changes: 2 additions & 2 deletions demo/GoogleIMAQs/Info.plist
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>GoogleIMAQs</string>
<key>CFBundleIdentifier</key>
<string>net.naxam.googleimaqs</string>
<string>com.highviewsoft.googleimaqs</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
Expand Down
219 changes: 215 additions & 4 deletions demo/GoogleIMAQs/ViewController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using System;

using AVFoundation;
using AVKit;
using Foundation;
using UIKit;
using GoogleIMA;

namespace GoogleIMAQs
{
public partial class ViewController : UIViewController
{
public AVPlayer ContentPlayer { get; set; }
public IMAAdsLoader AdsLoader { get; set; }
public IMAAVPlayerContentPlayhead ContentPlayhead { get; set; }
public IMAAdsManager AdsManager { get; set; }
public const string TestContentUrl_MP4 = "https://0.s3.envato.com/h264-video-previews/80fad324-9db4-11e3-bf3d-0050569255a8/490527.mp4";
public const string TestAdTagUrl = "https://test.bopodastaging.top/vmap/70.xml";

protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
Expand All @@ -14,13 +24,214 @@ protected ViewController(IntPtr handle) : base(handle)
public override void ViewDidLoad()
{
base.ViewDidLoad();

this.SetupAdsLoader();
this.SetupContentPlayer();
// Perform any additional setup after loading the view, typically from a nib.
}

public override void DidReceiveMemoryWarning()
/// <summary>
/// Setups the content player.
/// </summary>
private void SetupContentPlayer()
{
NSUrl contentUrl = NSUrl.FromString(TestContentUrl_MP4);

this.ContentPlayer = AVPlayer.FromUrl(contentUrl);

AVPlayerViewController controller = new AVPlayerViewController();
controller.Player = this.ContentPlayer;

AddChildViewController(controller);
View.AddSubview(controller.View);
controller.View.Frame = View.Frame;

this.ContentPlayhead = new IMAAVPlayerContentPlayhead(this.ContentPlayer);
NSNotificationCenter.DefaultCenter.AddObserver(observer:this,
aSelector: new ObjCRuntime.Selector("contentDidFinishPlaying:"),
aName: AVPlayerItem.DidPlayToEndTimeNotification,
anObject: this.ContentPlayer.CurrentItem);

this.RequestAds();
}

/// <summary>
/// Setups the ads loader.
/// </summary>
private void SetupAdsLoader()
{
IMASettings settings = new IMASettings()
{
Language = "zh-CN"
};
this.AdsLoader = new IMAAdsLoader(settings);
this.AdsLoader.Delegate = new MYPlayerAdsLoaderDelegate(new WeakReference<ViewController>(this));
}

/// <summary>
/// Requests the ads.
/// </summary>
private void RequestAds()
{
IMAAdDisplayContainer adDisplayContainer = new IMAAdDisplayContainer(this.View, null);
IMAAdsRequest request = new IMAAdsRequest(TestAdTagUrl, adDisplayContainer, this.ContentPlayhead, null);

this.AdsLoader.RequestAdsWithRequest(request);
}

/// <summary>
/// Contents the did finish playing.
/// </summary>
/// <param name="notification">Notification.</param>
[Export("contentDidFinishPlaying:")]
private void ContentDidFinishPlaying(NSNotification notification)
{
if(notification.Object == this.ContentPlayer?.CurrentItem)
{
this.AdsLoader.ContentComplete();
}
}
}

/// <summary>
/// Player ads loader delegate.
/// </summary>
public class MYPlayerAdsLoaderDelegate : IMAAdsLoaderDelegate
{
private ViewController weakSelf;

public MYPlayerAdsLoaderDelegate(WeakReference<ViewController> parent)
{
if (parent.TryGetTarget(out ViewController controller))
{
weakSelf = controller;
}
}

/// <summary>
/// Adses the loaded with data.
/// </summary>
/// <param name="loader">Loader.</param>
/// <param name="adsLoadedData">Ads loaded data.</param>
public override void AdsLoadedWithData(IMAAdsLoader loader, IMAAdsLoadedData adsLoadedData)
{
if (weakSelf == null)
return;
// Grab the instance of the IMAAdsManager and set ourselves as the delegate.
weakSelf.AdsManager = adsLoadedData.AdsManager;
weakSelf.AdsManager.Delegate = new MYPlayerAdsManagerDelegate(new WeakReference<ViewController>(weakSelf));
// Create ads rendering settings to tell the SDK to use the in-app browser.
IMAAdsRenderingSettings adsRenderingSettings = new IMAAdsRenderingSettings();
adsRenderingSettings.WebOpenerDelegate = new MYPlayerWebOpenerDelegate(new WeakReference<ViewController>(weakSelf));
adsRenderingSettings.WebOpenerPresentingController = weakSelf;
weakSelf.AdsManager.InitializeWithAdsRenderingSettings(adsRenderingSettings);
}

/// <summary>
/// Faileds the with error data.
/// </summary>
/// <param name="loader">Loader.</param>
/// <param name="adErrorData">Ad error data.</param>
public override void FailedWithErrorData(IMAAdsLoader loader, IMAAdLoadingErrorData adErrorData)
{
if (weakSelf == null)
return;
System.Diagnostics.Debug.WriteLine(adErrorData.AdError.Message);
weakSelf.ContentPlayer?.Play();
}
}

/// <summary>
/// Player ads manager delegate.
/// </summary>
public class MYPlayerAdsManagerDelegate : IMAAdsManagerDelegate
{
private ViewController weakSelf;
public MYPlayerAdsManagerDelegate(WeakReference<ViewController> parent)
{
if (parent.TryGetTarget(out ViewController controller))
{
weakSelf = controller;
}
}

/// <summary>
/// Adses the manager.
/// </summary>
/// <param name="adsManager">Ads manager.</param>
/// <param name="event">Event.</param>
public override void AdsManager(IMAAdsManager adsManager, IMAAdEvent @event)
{
if (@event.Type == IMAAdEventType.Loaded)
{
adsManager.Start();
}
else if(@event.Type == IMAAdEventType.Clicked)
{
adsManager.Pause();
}
}

/// <summary>
/// Adses the manager failed with error data.
/// </summary>
/// <param name="adsManager">Ads manager.</param>
/// <param name="error">Error.</param>
public override void AdsManager(IMAAdsManager adsManager, IMAAdError error)
{
if (weakSelf == null)
return;
System.Diagnostics.Debug.WriteLine(error.Message);
weakSelf.ContentPlayer?.Play();
}

/// <summary>
/// Adses the manager did request content pause.
/// </summary>
/// <param name="adsManager">Ads manager.</param>
public override void AdsManagerDidRequestContentPause(IMAAdsManager adsManager)
{
if (weakSelf == null)
return;
// The SDK is going to play ads, so pause the content.
weakSelf.ContentPlayer?.Pause();
}

/// <summary>
/// Adses the manager did request content resume.
/// </summary>
/// <param name="adsManager">Ads manager.</param>
public override void AdsManagerDidRequestContentResume(IMAAdsManager adsManager)
{
if (weakSelf == null)
return;
// The SDK is done playing ads (at least for now), so resume the content.
weakSelf.ContentPlayer?.Play();
}
}

/// <summary>
/// Player web opener delegate.
/// </summary>
public class MYPlayerWebOpenerDelegate : IMAWebOpenerDelegate
{
private ViewController weakSelf;
public MYPlayerWebOpenerDelegate(WeakReference<ViewController> parent)
{
if (parent.TryGetTarget(out ViewController controller))
{
weakSelf = controller;
}
}

/// <summary>
/// Webs the opener did close in app browser.
/// </summary>
/// <param name="webOpener">Web opener.</param>
public override void WebOpenerDidCloseInAppBrowser(NSObject webOpener)
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
System.Diagnostics.Debug.WriteLine("WebOpenerDidCloseInAppBrowser");
weakSelf.AdsManager?.Resume();
}
}
}
Loading