[A] facebook share

This commit is contained in:
2025-01-17 16:15:48 +08:00
parent 90e54158f1
commit c576351bca
11 changed files with 609 additions and 19 deletions

View File

@@ -0,0 +1,88 @@
import Foundation
import FBSDKShareKit
import Pods_UnityFramework
@objc public class FBShareHelper : NSObject{
@objc public func FBShare(title: String, content:String, link : String){
guard let url = URL(string: link) else
{
NSLog("url faild")
return
}
let vc = UnityFramework.getInstance().appController().rootViewController
let c = ShareLinkContent()
c.quote = content
c.contentURL = url
let dialog = ShareDialog(
viewController: vc,
content: c,
delegate: FBShareHelperDelegate()
)
NSLog("show fb share dialog")
// Recommended to validate before trying to display the dialog
do {
try dialog.validate()
} catch {
print("fbshare faild ! \(error)")
}
dialog.show()
}
@objc public func MFBShare(title: String, content:String, link : String){
guard let url = URL(string: link) else
{
NSLog("url faild")
return
}
let c = ShareLinkContent()
c.quote = content
c.contentURL = url
let dialog = MessageDialog(content: c, delegate: FBShareHelperDelegate())
do {
try dialog.validate()
} catch {
print("messenger share faild ! \(error)")
}
if(dialog.canShow)
{
dialog.show();
}
else
{
print("messenger share faild !")
}
}
}
class FBShareHelperDelegate: SharingDelegate
{
public func sharer(_ sharer: any FBSDKShareKit.Sharing, didCompleteWithResults results: [String : Any]) {
print("Share success \(results)")
SendToUnity(success: true)
}
public func sharer(_ sharer: any FBSDKShareKit.Sharing, didFailWithError error: any Error) {
print("Share error \(error)")
SendToUnity(success: false)
}
public func sharerDidCancel(_ sharer: any FBSDKShareKit.Sharing) {
print("Share cancel")
SendToUnity(success: false)
}
private func SendToUnity(success:Bool)
{
let message = success ? "0" : "1"
UnityFramework.getInstance().sendMessageToGO(withName: "GameObje", functionName: "Func", message: message)
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 74efa0262dac947a2a445362dc59c406
guid: a4af00d7aeb9247deaac729b3df35036
PluginImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,13 +0,0 @@
//
// Hint.swift
// UnityFramework
//
// Created by bamboo tech on 2024/8/2.
//
import Foundation
struct SillyHint
{
var text = "Add This File for Complie, Do not delete";
}

View File

@@ -4,6 +4,7 @@
#import <GASDK/GAConstants.h>
#import <GASDK/GASDK.h>
#import "TYConfig.h"
#import "UnityFramework/UnityFramework-Swift.h"
#define TOKEN_ERROR @"-8"
extern "C" {
@@ -351,5 +352,25 @@ extern "C" {
}
void FBShareLink(const char* title, const char* content, const char* url)
{
NSLog(@"TYSdkInterface FBShareLink");
NSString *t = [[NSString alloc] initWithCString: title encoding:NSUTF8StringEncoding];
NSString *c = [[NSString alloc] initWithCString: content encoding:NSUTF8StringEncoding];
NSString *l = [[NSString alloc] initWithCString: url encoding:NSUTF8StringEncoding];
FBShareHelper *helper = [[FBShareHelper alloc] init];
[helper FBShareWithTitle:t content:c link:l];
}
void MessengerShareLink(const char* title, const char* content, const char* url)
{
NSLog(@"TYSdkInterface FBShareLink");
NSString *t = [[NSString alloc] initWithCString: title encoding:NSUTF8StringEncoding];
NSString *c = [[NSString alloc] initWithCString: content encoding:NSUTF8StringEncoding];
NSString *l = [[NSString alloc] initWithCString: url encoding:NSUTF8StringEncoding];
FBShareHelper *helper = [[FBShareHelper alloc] init];
[helper MFBShareWithTitle:t content:c link:l];
}
}