@implementation ASHTempViewController
#pragma mark - app logic
- (void)sendBroadcastWithSuccessBlock:(void (^)(void))successBlock
{
BOOL haveRead = [[NSUserDefaults standardUserDefaults] boolForKey:@"haveReadBroadcastTip"];
if (haveRead == NO) {
NSString *title = @"1、发布广播,全服玩家都可以看到;\n2、禁止发布反动、政治、色情、辱骂、广告等不良言论,否则将会遭到删除、封号处理。";
__weak typeof(self) wself = self;
[self showAlertWithMsg:title callback:^{
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"haveReadBroadcastTip"];
[wself showSendViewWithSuccessBlock:successBlock];
}];
} else {
[self showSendViewWithSuccessBlock:successBlock];
}
}
- (void)showSendViewWithSuccessBlock:(void(^)(void))successBlock
{
__weak typeof(self) wself = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"发送广播" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"说点什么...";
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"发送" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *msg = [[alertController textFields][0] text];
[wself sendBroadcast:msg successBlock:successBlock];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Canelled");
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)sendBroadcast:(NSString *)msg successBlock:(void(^)(void))successBlock
{
__weak typeof(self) wself = self;
[self sendBroadcastRequestWithMsg:msg successBlock:^{
//data operation
!successBlock ?: successBlock();
} failureBlock:^(NSError *error) {
[wself showAlertWithMsg:error.localizedDescription callback:nil];
}];
}
#pragma mark - networks
- (void)sendBroadcastRequestWithMsg:(NSString *)msg successBlock:(void(^)(void))successBlock failureBlock:(void(^)(NSError *error))failureBlock
{
//send request
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
!successBlock ?: successBlock();
});
}
#pragma mark - utils
- (void)showAlertWithMsg:(NSString *)msg callback:(void(^)(void))callback
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
!callback ?: callback();
}]];
[self presentViewController:alert animated:YES completion:nil];
}
@end
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.