zoukankan      html  css  js  c++  java
  • Unity的IOS接入新浪微博

    单机游戏如果没有服务端,那微博就是一个推广和讨论的好地方。

    首先,可以看一下雨松的教程:

    http://www.xuanyusong.com/archives/1794

    我用的Unity4.0的beta版,发现了不少问题:

    一、ViewControl的获得改变了:

    sGLViewController 变化为--》UnityGetGLViewController()

    二、游戏内截图所放的位置有变化:

    Application.persistentDataPath打印出来的是:
    /var/mobile/Applications/27F8B3B1-8E33-4196-8610-40D87D6E7F1A/Documents

    从IOS中读取的图片路径是:
    /var/mobile/Applications/27F8B3B1-8E33-4196-8610-40D87D6E7F1A/Library/Documentation/XX.png

    所以我一直无法发出图片。

    解决方式是:把路径从Unity3D中传出来。

    为了测试,我找了个把截屏的图放到手机相册里的代码。

    using UnityEngine;
     using System.Collections;
     using System.Runtime.InteropServices;
     
     public class IOSTestSDK : MonoBehaviour {
     
         [DllImport("__Internal")]
         private static extern void _AuthLogin();
         
         [DllImport("__Internal")]
         private static extern void _ScreenshotWriteToAlbum(string path);
         
         public static void ActivateButton()
         {
             if (Application.platform != RuntimePlatform.OSXEditor)
             {
                 //_PressButton();
                 
                 Debug.Log("Before _AuthLogin");
                 _AuthLogin();
                 Debug.Log("After _AuthLogin");
             }
         }
         
         public static void ScreenshotWriteToAlbum(string path)
         {
             _ScreenshotWriteToAlbum(path);
         }
     }
     
    NSString* imgPath;
    void
    _ScreenshotWriteToAlbum(const char* path) { //imgPath = [NSString stringWithUTF8String:path]; imgPath = [[NSString alloc] initWithCString:path encoding:NSStringEncodingConversionAllowLossy]; sendImg = [UIImage imageWithContentsOfFile:[NSString stringWithUTF8String:path]]; ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease]; NSMutableDictionary* metadata = [[[NSMutableDictionary alloc] init] autorelease]; [library writeImageToSavedPhotosAlbum:sendImg.CGImage metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) { if(error) { NSLog(@"Screenshot error -%@", error); } else { NSLog(@"Screenshot taken - %@", error); } }]; }
    -(void)engineDidLogIn:(WBEngine *)engine
     {
         // login success
     //    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
     //    NSString* path = [paths objectAtIndex:0];
     //    NSString* imagePath = [path stringByAppendingPathComponent:@"kitchen.png"];
         
      //   NSData* data = [NSData dataWithContentsOfFile:imagePath];
     //    UIImage* img = [UIImage imageWithData:data];
         
      //   NSLog(@"path: -%@",imgPath);
         UIImage* img = [UIImage imageWithContentsOfFile:imgPath];
     
         [weiboEngine sendWeiBoWithText:@"测试IOS发微博" image:img];
     }

    最后结果:

     

     

  • 相关阅读:
    JQury RadioButton
    Oracle 错误
    C#基础 ASP.NET基本技巧
    后台管理系统框架模版(静态页)
    复习串讲 day02:搭建邮件服务、空客户端、搭建数据库服务、数据库基础操作
    ENGINEER 004:Linux命令字的来源、alias别名设置
    ENGINEER 003:配置IPv6地址
    ENGINEER 002: 配置用户环境 --- 配置聚合连接
    ENGINEER 001:SELinux安全机制
    命令行基础
  • 原文地址:https://www.cnblogs.com/gameprogram/p/2751822.html
Copyright © 2011-2022 走看看