#import <UIKit/UIKit.h>
@implementation Untility : NSObject
static Untility *instance = nil;
+(Untility *)sharedInstance{
@synchronized(self) {
if(instance == nil) {
instance = [[[self class] alloc] init];
}
}
return instance;
}
- (void)loadImageFinished:(UIImage *)image
{
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:didFinishSavingWithError:contextInfo:),
(__bridge void *)self);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
//初始化提示框;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"保存成功" preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {}]];
//弹出提示框;
[[self getCurrentVC] presentViewController:alert animated:true completion:nil];
}
- (UIViewController *)getCurrentVC
{
UIViewController *result = nil;
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView *frontView = [[window subviews] objectAtIndex:0];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
result = nextResponder;
else
result = window.rootViewController;
return result;
}
@end
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <err.h>
extern "C"{
void SaveImageToSystemAlbum(const char* path){
UIImage* image = [UIImage imageWithContentsOfFile:[NSString stringWithUTF8String:path]];
[[Untility sharedInstance] loadImageFinished:image];
}
}
网友评论