<master> add fb sharing sample

This commit is contained in:
Rustam Zaitov 2014-02-19 16:01:35 +04:00
parent 2f34a3b047
commit d5fb303bb7
9 changed files with 530 additions and 0 deletions

35
Social/IOs/AppDelegate.cs Normal file
View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.FacebookConnect;
namespace Social
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
private UIWindow window;
private MainController _mainController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
_mainController = new MainController ();
window.RootViewController = _mainController;
window.MakeKeyAndVisible ();
return true;
}
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
return FBAppCall.HandleOpenURL (url, sourceApplication);
}
}
}

View File

@ -0,0 +1,6 @@
<?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>
</dict>
</plist>

214
Social/IOs/FrameContext.cs Normal file
View File

@ -0,0 +1,214 @@
using System;
using System.Drawing;
using MonoTouch.UIKit;
namespace Touch.Common
{
public class FrameContext
{
public UIView View;
public RectangleF Frame;
public RectangleF? ParentBounds;
public RectangleF? RelativeFrame;
public FrameContext(UIView view, UIView relativeView)
{
View = view;
Frame = View.Frame;
ParentBounds = View.Superview != null ? View.Superview.Bounds : (RectangleF?)null;
RelativeFrame = relativeView != null ? relativeView.Frame : (RectangleF?)null;
}
public void Commit()
{
View.Frame = Frame;
}
}
public static class FrameHelper
{
/// <summary>
/// Get FrameContext
/// </summary>
public static FrameContext Begin(this UIView view, UIView relativeView = null)
{
FrameContext fc = new FrameContext(view, relativeView);
return fc;
}
#region Coordinates and dimensions
public static FrameContext X(this FrameContext fc, float x)
{
fc.Frame.X = x;
return fc;
}
public static FrameContext Y(this FrameContext fc, float y)
{
fc.Frame.Y = y;
return fc;
}
public static FrameContext Width(this FrameContext fc, float width)
{
fc.Frame.Width = width;
return fc;
}
public static FrameContext Height(this FrameContext fc, float height)
{
fc.Frame.Height = height;
return fc;
}
#endregion
#region Alignment
public static FrameContext AlignLeft(this FrameContext fc, float dx = 0f)
{
fc.Frame.X = dx;
return fc;
}
public static FrameContext AlignLeft(this FrameContext fc, UIView relativeView, float dx = 0f)
{
fc.Frame.X = relativeView.Frame.X + dx;
return fc;
}
public static FrameContext AlignTop(this FrameContext fc, float topMargin = 0f)
{
fc.Frame.Y = topMargin;
return fc;
}
public static FrameContext AlignTop(this FrameContext fc, UIView relativeView, float topMargin = 0f)
{
return fc.AlignTop(relativeView.Frame, topMargin);
}
public static FrameContext AlignTop(this FrameContext fc, RectangleF relativeViewFrame, float topMargin = 0f)
{
fc.Frame.Y = relativeViewFrame.Y + topMargin;
return fc;
}
public static FrameContext AlignRight(this FrameContext fc, float rightMargin = 0f)
{
fc.Frame.X = fc.ParentBounds.Value.Width - fc.Frame.Width - rightMargin;
return fc;
}
public static FrameContext AlignRight(this FrameContext fc, UIView relativeView, float rightMargin = 0f)
{
fc.Frame.X = relativeView.Frame.Right - fc.Frame.Width - rightMargin;
return fc;
}
public static FrameContext AlignBottom(this FrameContext fc)
{
return fc.BMargin(0f);
}
public static FrameContext AlignBottom(this FrameContext fc, UIView relativeView, float bottomMargin = 0f)
{
fc.Frame.Y = relativeView.Frame.Bottom - fc.Frame.Height - bottomMargin;
return fc;
}
#endregion
#region Margin
public static FrameContext BMargin(this FrameContext fc, float bottomMargin)
{
fc.Frame.Y = fc.ParentBounds.Value.Height - fc.Frame.Height - bottomMargin;
return fc;
}
public static FrameContext LMargin(this FrameContext fc, float leftMargin)
{
fc.Frame.X = leftMargin;
return fc;
}
public static FrameContext TMagrin(this FrameContext fc, float topMargin)
{
fc.Frame.Y = topMargin;
return fc;
}
#endregion
#region Placement
public static FrameContext PlaceAbove(this FrameContext fc, UIView viewBelow, float dy = 0f)
{
fc.Frame.Y = viewBelow.Frame.Y - fc.Frame.Height + dy;
return fc;
}
public static FrameContext PlaceBelow(this FrameContext fc, float dy = 0f)
{
fc.Frame.Y = fc.ParentBounds.Value.Height + dy;
return fc;
}
public static FrameContext PlaceBelow(this FrameContext fc, UIView viewAbove, float dy = 0f)
{
fc.Frame.Y = viewAbove.Frame.Bottom + dy;
return fc;
}
public static FrameContext PlaceRight(this FrameContext fc, UIView pivot, float dx = 0f)
{
fc.Frame.X = pivot.Frame.Right + dx;
return fc;
}
public static FrameContext CenterH(this FrameContext fc)
{
fc.Frame.X = (fc.ParentBounds.Value.Width - fc.Frame.Width) / 2;
return fc;
}
public static FrameContext CenterV(this FrameContext fc)
{
fc.Frame.Y = (fc.ParentBounds.Value.Height - fc.Frame.Height) / 2;
return fc;
}
/// <summary>
/// Расплолагает view левее центра родителя. Есть возможность сдвига на dx
/// </summary>
public static FrameContext LeftOfCenter(this FrameContext fc, float dx = 0f)
{
fc.Frame.X = fc.ParentBounds.Value.Width / 2 + dx;
return fc;
}
#endregion
#region Filling
public static FrameContext FillHorizontally(this FrameContext fc, float left = 0f, float right = 0f)
{
fc.Frame.X = left;
fc.Frame.Width = fc.ParentBounds.Value.Width - left - right;
return fc;
}
public static FrameContext FillBelow(this FrameContext fc)
{
float height = fc.ParentBounds.Value.Height - fc.Frame.Top;
fc.Frame.Height = height;
return fc;
}
#endregion
#region Movement
public static FrameContext MoveY(this FrameContext fc, float dy)
{
fc.Frame.Y += dy;
return fc;
}
#endregion
}
}

35
Social/IOs/Info.plist Normal file
View File

@ -0,0 +1,35 @@
<?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>CFBundleDisplayName</key>
<string>Social</string>
<key>CFBundleIdentifier</key>
<string>com.touchin.social</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>6.0</string>
<key>FacebookAppID</key>
<string>450576355025756</string>
<key>FacebookDisplayName</key>
<string>rzaitov</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb450576355025756</string>
</array>
</dict>
</array>
</dict>
</plist>

Binary file not shown.

19
Social/IOs/Main.cs Normal file
View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Social
{
public class Application
{
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}

View File

@ -0,0 +1,77 @@
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.FacebookConnect;
using Touch.Common;
namespace Social
{
public class MainController : UIViewController
{
private UIButton _fbShare;
public MainController ()
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
View.BackgroundColor = UIColor.White;
_fbShare = new UIButton ();
_fbShare.TouchUpInside += OnLoginClicked;
_fbShare.SetTitle("Share in Facebook", UIControlState.Normal);
_fbShare.SetTitleColor (UIColor.White, UIControlState.Normal);
_fbShare.BackgroundColor = UIColor.Blue;
_fbShare.SizeToFit ();
View.AddSubview (_fbShare);
_fbShare.Begin().MoveY(50).LMargin(20).Commit();
}
private void OnLoginClicked (object sender, EventArgs e)
{
FBShareDialogParams shareParams = new FBShareDialogParams ()
{
Link = NSUrl.FromString("http://touchin.ru/"),
Name = "Touch instinct",
Caption = "Greatest mobile apps for you",
Description = "Touch instinct team work for you"
};
if (FBDialogs.CanPresentShareDialog (shareParams))
PresentFacebookShareDialog (shareParams);
else
;
}
private void PresentFacebookShareDialog(FBShareDialogParams shareParams)
{
FBDialogs.PresentShareDialog(shareParams, null, FBDialogAppCallCompletion);
}
private void FBDialogAppCallCompletion(FBAppCall call, NSDictionary results, NSError error)
{
// review results for fething additonal info such completed or canceled, post id etc.
// for more info https://developers.facebook.com/docs/ios/share#linkshare
if (error == null)
return;
Console.WriteLine (error.Code);
Console.WriteLine (error.DebugDescription);
Console.WriteLine (error.Description);
Console.WriteLine (error.Domain);
Console.WriteLine (error.UserInfo);
Console.WriteLine (error);
Console.WriteLine (call);
}
}
}

112
Social/IOs/Social.csproj Normal file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC0EE67C-0932-4C64-A5D7-6714994CA602}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>Social</RootNamespace>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<AssemblyName>Social</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchDebug>true</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<MtouchLink>None</MtouchLink>
<ConsolePause>false</ConsolePause>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
<IpaPackageName>
</IpaPackageName>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhone\Ad-Hoc</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<BuildIpa>true</BuildIpa>
<CodesignProvision>Automatic:AdHoc</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhone\AppStore</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Distribution</CodesignKey>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<ConsolePause>false</ConsolePause>
<CodesignProvision>Automatic:AppStore</CodesignProvision>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
<Reference Include="MonoTouch.FacebookConnect">
<HintPath>Libs\MonoTouch.FacebookConnect.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Entitlements.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="MainController.cs" />
<Compile Include="FrameContext.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

32
Social/Social.sln Normal file
View File

@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Social", "IOs\Social.csproj", "{CC0EE67C-0932-4C64-A5D7-6714994CA602}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
Ad-Hoc|iPhone = Ad-Hoc|iPhone
AppStore|iPhone = AppStore|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.AppStore|iPhone.ActiveCfg = AppStore|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.AppStore|iPhone.Build.0 = AppStore|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Debug|iPhone.ActiveCfg = Debug|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Debug|iPhone.Build.0 = Debug|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Release|iPhone.ActiveCfg = Release|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Release|iPhone.Build.0 = Release|iPhone
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{CC0EE67C-0932-4C64-A5D7-6714994CA602}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = IOs\Social.csproj
EndGlobalSection
EndGlobal