Опираясь на ту же проблему, я решил пойти альтернативным путем: используйте QLPreviewRequestCreateContext, чтобы получить контекст, в котором можно сделать мое изображение в:
QLPreviewRequestRef preview; // The preview request passed to GeneratePreviewForURL()
CGImageRef image; // Create your CGImage however you like
CGSize size = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
CGContextRef ctxt = QLPreviewRequestCreateContext(preview, size, YES, nil);
CGContextDrawImage(ctxt, CGRectMake(0, 0, size.width, size.height), image);
QLPreviewRequestFlushContext(preview, ctxt);
CGContextRelease(ctxt);
По крайней мере, это работает ...
Вы должны использовать rxjs Subject
, чтобы выдавать значения всякий раз, когда в сервисном вызове происходит ошибка. Вы должны вызвать метод next()
.
@Injectable({
providedIn: 'root'
})
export class Service{
public notify$ = new Subject<any>();
doSomething(): Observable<any> {
return this.http.get<AA>(URL, options).pipe(
connectToThirdPArtyService();
}),
this.notify$.next(true);
);
}
В вашем компоненте вы должны слушать notify $ subject следующим образом, используя метод subscribe
, всякий раз, когда значение выдается с использованием метода next
, вызывается метод подписки в вашем компоненте сделать что-то внутри notify$
подписки
export class notification implements OnInit {
constructor(public service:Service) { }
ngOnInit() {
this.service.notify$.subscribe(messages => { DoSomethig(); });
}
}
Вы можете использовать субъект поведения, чтобы сделать это.
service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable()
export class DataService {
private messageSource = new BehaviorSubject('0');
currentMessage = this.messageSource.asObservable();
constructor() { }
changeNotification(number) {
this.messageSource.next(number)
}
}
parent.component.ts (Компонент уведомлений в вашем случае)
import { Component, OnInit } from '@angular/core';
import { DataService } from "../data.service";
@Component({
selector: 'app-parent',
template: `
{{message}}
`,
styleUrls: ['./sibling.component.css']
})
export class ParentComponent implements OnInit {
message:string;
constructor(private data: DataService) { }
ngOnInit() {
this.data.changeNotification.subscribe(number => this.number = number)
}
}
Когда происходит сбой, вы можете нажать на тему поведения, как,
constructor(private data: DataService) { }
onFailure() {
this.data.changeNotification("1")
}
У вас может быть номер на уровне обслуживания, и вы можете увеличивать его при сбое и нажимать на него или как хотите.