繁体   English   中英

iOS中斜杠面临的问题

[英]Facing Issues with slash keyboard in iOS

我正在使用iOS聊天应用程序。 我想使用斜杠键盘。 您能指导我如何在我的iOS编程中使用gif图像。 实际上,从斜杠选择gif文件后获得的链接没有在代码中提供图像。 请指导我。

对于例如http://tapslash.com/m/giphy/NycV9yzKiiBR6,这是gif链接,但我无法在Xcode中获取图像。

NSURL *url=[NSURL URLWithString:@"http://tapslash.com/m/giphy/10k8HMhtzzk73W"];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * image = [UIImage imageWithData:imageData];

总是得到零图像

该链接不是指向图像的链接,而是链接到包含该图像的网页。 要从链接中获取NSData,它必须以.gif或类似的结尾。 在您的示例代码中,我将其更改为

NSURL *url=[NSURL URLWithString:@"http://media0.giphy.com/media/10k8HMhtzzk73W/giphy.gif"];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * image = [UIImage imageWithData:imageData];

如果您具有URL http://tapslash.com/m/giphy/10k8HMhtzzk73Whttp://tapslash.com/m/giphy/10k8HMhtzzk73W获取它的.gif url,必须在结尾处添加该部分。

NSArray *splitURL = [stringContainingURL componentsSeparatedBy:@"/"];
NSString *identifier = [splitURL lastObject]; // Written in browser, not sure if exists. If not use [splitURL objectAtIndex:splitURL.count - 1];

NSString *goodURLString = [NSString stringWithFormat:@"http://media0.giphy.com/media/%@/giphy.gif", identifier];

// Should return:  http://media0.giphy.com/media/10k8HMhtzzk73W/giphy.gif

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM