summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPliable Pixels <pliablepixels@gmail.com>2020-03-14 09:25:29 -0400
committerPliable Pixels <pliablepixels@gmail.com>2020-03-14 09:25:29 -0400
commit58c7e55399591a6a487a9519624bf1e8ad6ca20f (patch)
tree8f376ee677f9ac424ee7e9e26b2e4fa98081f9f0
parente484e767ebfdb729e0f87d2dce1094ae6b7dae94 (diff)
Allow mp4 files in notification
-rwxr-xr-xbuild_ios.sh23
-rw-r--r--config.xml8
-rw-r--r--etc/NotificationService.m114
-rw-r--r--package.json10
4 files changed, 102 insertions, 53 deletions
diff --git a/build_ios.sh b/build_ios.sh
index 529f2a54..9598aab9 100755
--- a/build_ios.sh
+++ b/build_ios.sh
@@ -1,10 +1,25 @@
echo "*** Using old build system due to XCode 10 issues ** "
echo "see https://forum.ionicframework.com/t/how-to-build-ionic-cordova-with-xcode-10/142044"
-ionic cordova plugin remove cordova-plugin-ionic-webview 2>/dev/null
-ionic cordova plugin add https://github.com/pliablepixels/cordova-plugin-ionic-webview.git
-cordova plugin remove cordova-plugin-media-pp-fork
-cordova plugin add cordova-plugin-media-pp-fork
+if [ "$1" != "skip" ]
+then
+ ionic cordova plugin remove cordova-plugin-ionic-webview 2>/dev/null
+ ionic cordova plugin add https://github.com/pliablepixels/cordova-plugin-ionic-webview.git
+ cordova plugin remove cordova-plugin-media-pp-fork
+ cordova plugin add cordova-plugin-media-pp-fork
+else
+ echo "Skipping plugin update process. Make sure you did not build for Android before this"
+fi
+
+echo
+echo "-- Copying manual files --"
+
+cp ./etc/NotificationService.m ./platforms/ios/zmNinjaNotification/NotificationService.m
+if [ $? -ne 0 ]
+then
+ echo "Error copying over Notification Service"
+ exit 1
+fi
#echo "--- readding certificate plugin to make sure... ---"
#ionic cordova plugin remove cordova-plugin-certificates
diff --git a/config.xml b/config.xml
index 08af12d5..ee055fd8 100644
--- a/config.xml
+++ b/config.xml
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
-<widget android-packageName="com.pliablepixels.zmninja_pro" id="com.pliablepixels.zmninja_pro" ios-CFBundleIdentifier="com.pliablepixels.zmninja-pro" version="1.3.090" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
+<widget android-packageName="com.pliablepixels.zmninja_pro" id="com.pliablepixels.zmninja_pro" ios-CFBundleIdentifier="com.pliablepixels.zmninja-pro" version="1.3.091" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>zmNinja</name>
<description>
High performance ZoneMinder client
@@ -176,10 +176,10 @@
<variable name="ANDROID_SUPPORT_V13_VERSION" value="27.+" />
<variable name="FCM_VERSION" value="17.0.+" />
</plugin>
- <plugin name="cordova-plugin-media-pp-fork" spec="^1.0.2-dev" />
- <engine name="android" spec="8.0.0" />
- <engine name="ios" spec="^5.0.1" />
<plugin name="cordova-plugin-ionic-webview" spec="https://github.com/pliablepixels/cordova-plugin-ionic-webview.git">
<variable name="ANDROID_SUPPORT_ANNOTATIONS_VERSION" value="27.+" />
</plugin>
+ <plugin name="cordova-plugin-media-pp-fork" spec="^1.0.2-dev" />
+ <engine name="android" spec="8.0.0" />
+ <engine name="ios" spec="^5.0.1" />
</widget>
diff --git a/etc/NotificationService.m b/etc/NotificationService.m
index ef03a273..c30eaed9 100644
--- a/etc/NotificationService.m
+++ b/etc/NotificationService.m
@@ -28,63 +28,97 @@
// If there is no image in the payload than
// the code will still show the push notification.
if (userInfo == nil || userInfo[@"image_url_jpg"] == nil) {
- self.contentHandler(self.bestAttemptContent);
+ NSLog(@"zmNinja Notification: Did not get a payload or image");
+ [self contentComplete];
return;
}
- NSString *attachmentMedia = userInfo[@"image_url_jpg"];
- //NSLog (@"Your attachment URL is: %@", attachmentMedia);
+ NSString *mediaUrl = userInfo[@"image_url_jpg"];
+ // if (mediaType == nil) {
+ // NSLog(@"zmNinja Notification: No media type specified, assuming .jpg");
+ // mediaType = @".jpg";
+ // }
- // If there is an image in the payload, this part
- // will handle the downloading and displaying of the image.
- if (attachmentMedia) {
- NSURL *URL = [NSURL URLWithString:attachmentMedia];
- NSURLSession *LPSession = [NSURLSession sessionWithConfiguration:
- [NSURLSessionConfiguration defaultSessionConfiguration]];
- [[LPSession downloadTaskWithURL:URL completionHandler: ^(NSURL *temporaryLocation, NSURLResponse *response, NSError *error) {
- if (error) {
- NSLog(@"zmNinja Push: Error with downloading rich push: %@",
- [error localizedDescription]);
- self.contentHandler(self.bestAttemptContent);
- return;
- }
-
- NSString *fileType = [self determineType: [response MIMEType]];
- NSString *fileName = [[temporaryLocation.path lastPathComponent] stringByAppendingString:fileType];
- NSString *temporaryDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
- [[NSFileManager defaultManager] moveItemAtPath:temporaryLocation.path toPath:temporaryDirectory error:&error];
-
- NSError *attachmentError = nil;
- UNNotificationAttachment *attachment =
- [UNNotificationAttachment attachmentWithIdentifier:@""
- URL:[NSURL fileURLWithPath:temporaryDirectory]
- options:nil
- error:&attachmentError];
- if (attachmentError != NULL) {
- NSLog(@"zmNinja push: Error with the rich push attachment: %@",
- [attachmentError localizedDescription]);
- self.contentHandler(self.bestAttemptContent);
- return;
- }
- self.bestAttemptContent.attachments = @[attachment];
- self.contentHandler(self.bestAttemptContent);
- [[NSFileManager defaultManager] removeItemAtPath:temporaryDirectory error:&error];
- }] resume];
- }
+ // load the attachment
+ [self loadAttachmentForUrlString:mediaUrl
+
+ completionHandler:^(UNNotificationAttachment *attachment) {
+ if (attachment) {
+ self.bestAttemptContent.attachments = [NSArray arrayWithObject:attachment];
+ }
+ [self contentComplete];
+ }];
}
- (NSString*)determineType:(NSString *) fileType {
// Determines the file type of the attachment to append to NSURL.
-
+ //return @".gif";
+ // Determines the file type of the attachment to append to NSURL.
+ NSLog (@"zmNinja Notification: determineType got filetype=%@",fileType);
+ if ([fileType isEqualToString:@"image/jpeg"]){
+ NSLog (@"zmNinja Notification: returning JPG");
return @".jpg";
+ }
+ if ([fileType isEqualToString:@"video/mp4"]){
+ NSLog (@"zmNinja Notification: returning MP4");
+ return @".mp4";
+ }
+
+ if ([fileType isEqualToString:@"image/gif"]) {
+ NSLog (@"zmNinja Notification: returning GIF");
+ return @".gif";
+ }
+ if ([fileType isEqualToString:@"image/png"]) {
+ NSLog (@"zmNinja Notification: returning PNG");
+ return @".png";
+
+ }
+ NSLog (@"zmNinja Notification: unrecognized filetype, returning JPG");
+ return @".jpg";
}
+- (void)loadAttachmentForUrlString:(NSString *)urlString
+ completionHandler:(void(^)(UNNotificationAttachment *))completionHandler {
+
+ __block UNNotificationAttachment *attachment = nil;
+ NSURL *attachmentURL = [NSURL URLWithString:urlString];
+
+ NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
+ [[session downloadTaskWithURL:attachmentURL
+ completionHandler:^(NSURL *temporaryFileLocation, NSURLResponse *response, NSError *error) {
+ if (error != nil) {
+
+ NSLog(@"unable to add attachment: %@", error.localizedDescription);
+
+ } else {
+ NSString *fileType = [self determineType: [response MIMEType]];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSURL *localURL = [NSURL fileURLWithPath:[temporaryFileLocation.path stringByAppendingString:fileType]];
+ [fileManager moveItemAtURL:temporaryFileLocation toURL:localURL error:&error];
+
+ NSError *attachmentError = nil;
+ attachment = [UNNotificationAttachment attachmentWithIdentifier:@"" URL:localURL options:nil error:&attachmentError];
+ if (attachmentError) {
+
+ NSLog(@"unable to add attchment: %@", attachmentError.localizedDescription);
+
+ }
+ }
+ completionHandler(attachment);
+ }] resume];
+}
+
+- (void)contentComplete {
+ self.contentHandler(self.bestAttemptContent);
+}
+
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
+ NSLog (@"zmNinja Notification: Time about to expire, handing off to best attempt");
self.contentHandler(self.bestAttemptContent);
}
diff --git a/package.json b/package.json
index 3cfc328c..b112ba6b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "zmninjapro",
"description": "Home security mobile app for ZoneMinder",
- "version":"1.3.090",
+ "version": "1.3.090",
"displayName": "zmNinja",
"author": "Pliable Pixels",
"license": "custom see LICENSE.md",
@@ -59,10 +59,10 @@
"ANDROID_SUPPORT_V13_VERSION": "27.+",
"FCM_VERSION": "17.0.+"
},
- "cordova-plugin-media-pp-fork": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
- }
+ },
+ "cordova-plugin-media-pp-fork": {}
}
},
"dependencies": {
@@ -153,7 +153,7 @@
"productName": "zmninja-pro",
"compression": "normal",
"asar": true,
- "afterSign":"electron_js/notarize.js",
+ "afterSign": "electron_js/notarize.js",
"directories": {
"buildResources": "electron_js/icons"
},
@@ -226,4 +226,4 @@
]
}
}
-}
+} \ No newline at end of file