RoboVM已被RoboPods取代。因此,RoboVM已不再使用,那么现在该怎么办呢?
https://github.com/robovm/robovm-robopods/tree/master
如果想要使用roboVM分享text
,可以设置UIAvtivityViewController
类。
NSString textShare = new NSString("This is the text to share");
NSArray texttoshare = new NSArray(textShare);
UIActivityViewController share = new UIActivityViewController(texttoshare,null);
presentViewController(share, true, null);
如果您想分享文本、图片和应用,可以使用以下代码:
// Code goes here
NSURL imgUrl = new NSURL(EXTERNAL_IMG_URL);
NSData data = NSData.read(imgUrl);
UIImage image = new UIImage(data);
NSString appStoreUrl = new NSString(APP_STORE_URL);
NSString googleUrl = new NSString(GOOGLE_PLAY_URL);
NSString text = new NSString(TEXT_TO_SHARE);
NSArray<NSObject> texttoshare = new NSArray<NSObject>(text, image, appStoreUrl, googleUrl);
UIActivityViewController share = new UIActivityViewController(
texttoshare, null);
if (UIDevice.getCurrentDevice().getUserInterfaceIdiom() == UIUserInterfaceIdiom.Phone) {
//iPhone
iosApplication.getUIViewController().presentViewController(
share, true, null);
} else {
//iPad
UIPopoverController popover = new UIPopoverController(share);
UIView view = iosApplication.getUIViewController().getView();
CGRect rect = new CGRect(
view.getFrame().getWidth() / 2,
view.getFrame().getHeight() / 4,
0,
0);
popover.presentFromRectInView( rect, view, UIPopoverArrowDirection.Any, true);
}
以下代码可以通过邮件和Messenger发送动态的 .gif
图像,然而Twitter只能分享静态图像。public void shareGif(String path)
{
NSURL url = new NSURL(new File(path));
NSArray<NSObject> imageArray = new NSArray<NSObject>(image);
UIActivityViewController share = new UIActivityViewController(imageArray,null);
((IOSApplication)Gdx.app).getUIViewController().presentViewController(share, true, null);
}
以下是iOS通用分享代码,包含文本、链接和图片
:
@Override
public void share() {
NSArray<NSObject> items = new NSArray<>(
new NSString("Hey! Check out this mad search engine I use"),
new NSURL("https://www.google.com"),
new UIImage(Gdx.files.external("image.png").file())
);
UIActivityViewController uiActivityViewController = new UIActivityViewController(items, null);
((IOSApplication) Gdx.app).getUIViewController().presentViewController(uiActivityViewController, true, null);
}
RoboVM只适用于iOS,那么我们如何在使用LibGDX时在Android上使用它呢?在iOS上,使用带有RoboPods的RoboVM,而在Android上使用Google Play服务。不同的设备需要不同的代码。对于Android,将Android SDK集成到您的IDE中后,只需将Google Play服务库链接到Android项目即可。