[A] facebook share
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74efa0262dac947a2a445362dc59c406
|
||||
guid: a4af00d7aeb9247deaac729b3df35036
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user