- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有谁知道如何在 iOS 中禁用 SLComposeViewController 的完成声音?
在用户发布消息后播放声音,例如 Facebook 或推特。
最佳答案
您可以执行以下操作:
让 SLComposeViewController 在按下“发送”时不发送推文。并手动发送推文。
1.递归遍历所有 View 并找到“发送”按钮// UIButton with width 50px
- (UIButton *)tweetSendButton:(UIView *)view
{
for (UIView * subview in view.subviews)
{
if ([subview isKindOfClass:[UIButton class]]
&& subview.bounds.size.width == 50)
{
return (UIButton *)subview;
}
UIButton * button = [self tweetSendButton:subview];
if (button) return button;
}
return nil;
}
...
UIButton * sendButton = [self tweetSendButton:_tweetController.view];
2. 删除目标 SLComposeViewController 的所有操作
NSArray * actions = [sendButton actionsForTarget:_tweetController forControlEvent:UIControlEventTouchUpInside];
for (NSString * action in actions)
[sendButton removeTarget:_tweetController action:NSSelectorFromString(action) forControlEvents:UIControlEventTouchUpInside];
3. 为 UIControlEventTouchUpInside 事件添加自己的 Action
[sendButton addTarget:self action:@selector(sendCustomTweet:) forControlEvents:UIControlEventTouchUpInside];
4. 当按下“发送”按钮时,使用此方法获取文本和帐户(如有必要):
....
UITextView * textView = [self tweetTextView:self.tweetController.view];
UIButton * accountButton = [self twitterAccountButton:self.tweetController.view];
NSString * tweetText = textView.text;
NSString * tweetAccount = [accountButton.titleLabel.text substringFromIndex:1]; // skip @ char
....
5. 以下是这些方法:
// Single UITextView
- (UITextView *)tweetTextView:(UIView *)view
{
for (UIView * subview in view.subviews)
{
if ([subview isMemberOfClass:[UITextView class]])
return (UITextView *)subview;
UITextView * textView = [self tweetTextView:subview];
if (textView) return textView;
}
return nil;
}
// UIButton witch starts from @
- (UIButton *)twitterAccountButton:(UIView *)view
{
for (UIView * subview in view.subviews)
{
if ([subview isKindOfClass:[UIButton class]])
{
UIButton * button = (UIButton *)subview;
if (button.titleLabel.text && [button.titleLabel.text rangeOfString:@"@"].location == 0)
return button;
}
UIButton * button = [self twitterAccountButton:subview];
if (button) return button;
}
return nil;
}
6.手动发送推文
- (void)sendTweet:(NSString *)text fromAccount:(NSString *)account withArtwork:(UIImage *)artwork
{
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(!granted) return;
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
for(ACAccount *twitterAccount in accountsArray)
{
if (account && ([account compare:twitterAccount.username options:(NSCaseInsensitiveSearch)] != 0))
continue;
// Create a request, which in this example, posts a tweet to the user's timeline.
// This example uses version 1 of the Twitter API.
// This may need to be changed to whichever version is currently appropriate.
NSString * method = artwork ? @"update_with_media" : @"update";
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/%@.json",method,nil]];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:url parameters:@{@"status":text} requestMethod:TWRequestMethodPOST];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
if (artwork)
{
NSData * data = UIImageJPEGRepresentation(artwork, 0.8);
[postRequest addMultiPartData:data withName:@"media" type:@"JPG"];
}
// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (urlResponse.statusCode == 200)
{
NSLog(@"Tweet sent successfully!");
}
else
{
NSDictionary * json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSLog(@"Tweet sending failed with error: %@", json);
}
}];
}
}];
}
关于ios - 如何禁用 SLComposeViewController(Facebook、Twitter 等)的完成声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13191365/
在 iOS 7 应用程序中呈现 SLComposeViewController 时,位置字段始终默认为“无”,即使关联的 Twitter 和/或 Facebook 帐户具有允许显示其当前位置的隐私设置
当我在没有网络的情况下查看 twitter(iOS5 和 6)时,它会在完成处理程序中返回 SLComposeViewControllerResultDone。是否有任何解决方案可以显示成功的结果?任
SLComposeViewController 在呈现后需要 3-4 秒才能出现。但是 presentViewController:(UIViewController *) animated:(BOO
我正在尝试使用 SLComposeViewController 在 iOS 应用程序中将帖子分享到 Facebook。但是,如果我在帖子上点击取消,“完成”的结果将返回到完成处理程序而不是“取消”。当
我注意到 Mobile Safari 的 Twitter 和 Facebook 分享添加了当前页面的屏幕截图而没有真正分享它,例如: 我试图通过 SLComposeViewController 复制它
我一直在使用此代码进行 Twitter 发布。 SLComposeViewController *fbController=[SLComposeViewController composeViewCo
如何将 UIKeyboardAppearanceDark 与 SLComposeViewController 一起使用? SLComposeViewController 类向用户呈现一个 View ,
是否可以使用 SLComposeViewController 回复推文?有人做过吗? 最佳答案 好吧,我们就到这里吧。首先,我们需要在每次点击回复按钮时生成一个 SLComposeViewContro
我即将通过 iTunes Connect 提交我的应用程序,在填写信息时,我注意到隐私政策的可选 URL。我的应用程序不会从我的任何用户那里收集个人信息,但它确实允许用户使用社交框架中的 SLComp
现在,我们的代码设置为从 获取文本。 UITextField 作为 setInitialText 用于 Facebook/Twitter 帖子。 我们要做的是:在 Facebook/Twitter 帖
This question already has answers here: Prevent users from modifying part of the text in SLComposeVi
我正在开发一个需要社交框架支持的应用程序。所以我决定用这个 SLComposeViewController *cntrlr = [[SLComposeViewController alloc]init
使用SLComposeViewController/SLServiceTypeTwitter时,是否可以附加声音或视频?对象实例化如下: SLComposeViewController *tweetC
我正在使用 SLComposeViewController 将文章发布到 facebook 墙。当在设备设置中关闭 facebook 的应用程序权限时,SLComposeViewController
好的,我有一个单一 View 的 iOS 应用程序。在 View Controller 内部,我有一个附加到 Storyboard 中的按钮的方法。这是按下按钮时的方法: - (IBAction)tw
我正在尝试创建 SLComposeViewController 的子类,以便在我的案例中更易于使用。当我尝试创建 required init 并调用 super.init(forServiceType
我正在使用 SLComposeViewController 在 facebook 和 twitter 上分享。当我执行操作然后打开对话框,但对话框中没有出现任何文本。 最佳答案 自从 Facebook
我在使用 Twitter SLComposeViewController 时遇到了一个奇怪的问题。我现在在 imagePickerController 方法中有一个错误,显示“发送 void 到不兼容
将图像添加到 SLComposeViewController 时,图像会显示在 SLComposeViewController View 的右侧。然而,它显示在下面(如下层)另一个看起来像指南针的默认
我正在代表客户构建一个 IOS7 native 应用程序 - 它适用于健身教练。 客户可以在社交上分享进度更新的简短请求 - 其中包括指向教师网站的链接以帮助宣传,例如 - 'Joe ran 3000
我是一名优秀的程序员,十分优秀!