293 lines
10 KiB
Mathematica
Raw Normal View History

2023-07-10 17:50:31 +08:00
#import "AppDelegate.h"
2023-07-10 17:50:31 +08:00
#import "GeneratedPluginRegistrant.h"
2023-10-14 17:08:25 +08:00
#import "CommonDefine.h"
#import "XSFlutterManager.h"
#import "Sformat.h"
#import "Pub.h"
#import "Msg.h"
#import "VideoTalkManager.h"
#import <UserNotifications/UserNotifications.h>
#import "BaseViewController.h"
@interface AppDelegate()
@end
@implementation AppDelegate {
SystemSoundID okSound;
SystemSoundID noticeSound;
SystemSoundID errorSound;
SystemSoundID alarmSound;
SystemSoundID ringSound;
}
2023-07-10 17:50:31 +08:00
@synthesize sysinfo;
@synthesize db;
2023-07-10 17:50:31 +08:00
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initCloudPush];
[CloudPushSDK sendNotificationAck:launchOptions];
XSFlutterManager *VC = [[XSFlutterManager alloc] init];
self.window.rootViewController = VC;
[self.window makeKeyAndVisible];
2023-11-01 18:03:50 +08:00
//
//[self initSound];
//_udp = [[UdpHelper alloc] init];
//[_udp Open];
//_talk = [[talk_Class alloc] init];
//sysinfo.launchtime = [Sformat timestamp];
return YES;
2023-07-10 17:50:31 +08:00
}
- (void)initCloudPush {
// SDK
[CloudPushSDK asyncInit:@"333904046" appSecret:@"3eead09a7fc7416cb4082319aa6f48c6" callback:^(CloudPushCallbackResult *res) {
if (res.success) {
NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
} else {
NSLog(@"Push SDK init failed, error: %@", res.error);
}
}];
}
/**
* deviceToken
*
* @param application
*/
- (void)registerAPNS:(UIApplication *)application {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
// iOS 8 Notifications
[application registerUserNotificationSettings:
[UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
[application registerForRemoteNotifications];
}
else {
// iOS < 8 Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
}
/*
* deviceTokenCloudPush
*/
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[CloudPushSDK registerDevice:deviceToken withCallback:^(CloudPushCallbackResult *res) {
if (res.success) {
NSLog(@"Register deviceToken success.");
} else {
NSLog(@"Register deviceToken failed, error: %@", res.error);
}
}];
}
/*
*
*/
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
}
/**
*
*/
- (void)registerMessageReceive {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMessageReceived:)
name:@"CCPDidReceiveMessageNotification"
object:nil];
}
/**
*
*
* @param notification
*/
- (void)onMessageReceived:(NSNotification *)notification {
CCPSysMessage *message = [notification object];
NSString *title = [[NSString alloc] initWithData:message.title encoding:NSUTF8StringEncoding];
NSString *body = [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding];
NSLog(@"Receive message title: %@, content: %@.", title, body);
}
//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// // App
// // [CloudPushSDK handleLaunching:launchOptions];(Deprecated from v1.8.1)
// [CloudPushSDK sendNotificationAck:launchOptions];
// return YES;
//}
/*
* App
*/
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
NSLog(@"Receive one notification.");
// APNS
NSDictionary *aps = [userInfo valueForKey:@"aps"];
//
NSString *content = [aps valueForKey:@"alert"];
// badge
NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
//
NSString *sound = [aps valueForKey:@"sound"];
// Extras
NSString *Extras = [userInfo valueForKey:@"Extras"]; //Extraskey
NSLog(@"content = [%@], badge = [%ld], sound = [%@], Extras = [%@]", content, (long)badge, sound, Extras);
// iOS badge 0
application.applicationIconBadgeNumber = 0;
//
// [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1)
[CloudPushSDK sendNotificationAck:userInfo];
}
- (void)initSound
{
CFURLRef okURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ok" ofType:@"wav"]]);
CFURLRef noticeURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
CFURLRef errURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"err" ofType:@"wav"]]);
CFURLRef alarmURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"]]);
CFURLRef ringURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notice" ofType:@"wav"]]);
AudioServicesCreateSystemSoundID(okURL, &okSound);
AudioServicesCreateSystemSoundID(noticeURL, &noticeSound);
AudioServicesCreateSystemSoundID(errURL, &errorSound);
AudioServicesCreateSystemSoundID(alarmURL, &alarmSound);
AudioServicesCreateSystemSoundID(ringURL, &ringSound);
AudioServicesPropertyID flag = 0; //0 means always play
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &okSound, sizeof(AudioServicesPropertyID), &flag);
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &noticeSound, sizeof(AudioServicesPropertyID), &flag);
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &errorSound, sizeof(AudioServicesPropertyID), &flag);
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &alarmSound, sizeof(AudioServicesPropertyID), &flag);
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(SystemSoundID), &ringSound, sizeof(AudioServicesPropertyID), &flag);
CFBridgingRelease(okURL);
CFBridgingRelease(noticeURL);
CFBridgingRelease(errURL);
CFBridgingRelease(alarmURL);
CFBridgingRelease(ringURL);
}
- (void)playSoundWith:(NSInteger)mode
{
dispatch_async(dispatch_get_main_queue(), ^{//线
if ([MPMusicPlayerController systemMusicPlayer].playbackState == MPMusicPlaybackStatePlaying) {
NSLog(@"play ServicesPlayAlertSound ...");
switch (mode) {
case SoundOK:
AudioServicesPlayAlertSound(self->okSound);
break;
case SoundNotice:
AudioServicesPlayAlertSound(self->noticeSound);
break;
case SoundError:
AudioServicesPlayAlertSound(self->errorSound);
break;
case SoundAlarm:
AudioServicesPlayAlertSound(self->alarmSound);
break;
case SoundRing:
AudioServicesPlayAlertSound(self->ringSound);
break;
default:
break;
}
}
else
{
NSLog(@"play ServicesPlaySystemSound ...");
switch (mode) {
case SoundOK:
AudioServicesPlaySystemSound(self->okSound);
break;
case SoundNotice:
AudioServicesPlaySystemSound(self->noticeSound);
break;
case SoundError:
AudioServicesPlaySystemSound(self->errorSound);
break;
case SoundAlarm:
AudioServicesPlayAlertSound(self->alarmSound);
break;
case SoundRing:
AudioServicesPlayAlertSound(self->ringSound);
break;
default:
break;
}
}
});
}
- (void)ring
{
if (!self.isBack)[self playaudio];
//if (!self.isBack)[self playSoundWith:SoundRing];
}
- (void)ring_stop
{
if(self.audioPlayer != nil) {
[self.audioPlayer stop];
self.audioPlayer = nil;
}
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
}
- (void)playaudio
{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
//
NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"ring1" ofType:@"mp3"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:musicPath];
//
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
//[url release];
[self.audioPlayer prepareToPlay];
[self.audioPlayer setVolume:.5];
self.audioPlayer.numberOfLoops = -1; // -1
[self.audioPlayer play]; //
NSLog(@"playaudio");
}
- (void)OpenDoorSucc:(NSString *)equid{
if(self.callOut){
[self.callOut alert:@"开门成功"];
}
[self playSoundWith:SoundOK];
[self.sysinfo SaveRecord:[Sformat timestamp] Type:@"开门" Equ:equid Img:@"" Note:@"成功"];
}
- (void)OpenDoorFail:(NSString *)equid{
if(self.callOut){
[self.callOut alert:@"开门失败"];
NSLog(@"通话中开门失败");
}
[self playSoundWith:SoundError];
[self.sysinfo SaveRecord:[Sformat timestamp] Type:@"开门" Equ:equid Img:@"" Note:@"失败"];
}
2023-07-10 17:50:31 +08:00
@end