Jon*_*ony 4 objective-c url-scheme ios instagram instagram-api
有没有办法将视频或照片直接发布到用户 Instagram 帐户的 Instagram 故事中?对于 Instagram 上的普通照片共享,您可以使用 URL Scheme 并直接打开编辑器。故事也有办法吗?
谢谢!
Tam*_*gel 11
Swift 4.2 版本的knshn 答案:
func shareBackgroundImage() {
let image = UIImage(imageLiteralResourceName: "backgroundImage")
if let pngImage = image.pngData() {
backgroundImage(pngImage, attributionURL: "http://your-deep-link-url")
}
}
func backgroundImage(_ backgroundImage: Data, attributionURL: String) {
// Verify app can open custom URL scheme, open if able
guard let urlScheme = URL(string: "instagram-stories://share"),
UIApplication.shared.canOpenURL(urlScheme) else {
// Handle older app versions or app not installed case
return
}
let pasteboardItems = [["com.instagram.sharedSticker.backgroundImage": backgroundImage,
"com.instagram.sharedSticker.contentURL": attributionURL]]
let pasteboardOptions: [UIPasteboard.OptionsKey: Any] = [.expirationDate: Date().addingTimeInterval(60 * 5)]
// This call is iOS 10+, can use 'setItems' depending on what versions you support
UIPasteboard.general.setItems(pasteboardItems, options: pasteboardOptions)
UIApplication.shared.open(urlScheme)
}
Run Code Online (Sandbox Code Playgroud)
Instagram 自 2018 年 3 月起正式支持此功能。https://developers.facebook.com/docs/instagram/sharing-to-stories/
对于 iOS:
您需要添加instagram-stories到LSApplicationQueriesSchemes应用程序的Info.plist.
此示例代码展示了如何向 Instagram 应用传递背景层图像资产和归因深层链接。
- (void)shareBackgroundImage {
[self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"])
attributionURL:@"http://your-deep-link-url"];
}
- (void)backgroundImage:(NSData *)backgroundImage
attributionURL:(NSString *)attributionURL {
// Verify app can open custom URL scheme, open if able
NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) {
// Assign background image asset and attribution link URL to pasteboard
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : backgroundImage,
@"com.instagram.sharedSticker.contentURL" : attributionURL}];
NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
// This call is iOS 10+, can use 'setItems' depending on what versions you support
[[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];
[[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
} else {
// Handle older app versions or app not installed case
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8601 次 |
| 最近记录: |