-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question - Sending attachments through IMCore #109
Comments
Yeah, we should be able to fully integrate with IMCore; I'd have to do quite a bit of testing to ensure that we didn't lose any functionality in the process. However, I'm not quite sure why that would be necessary. It would be somewhat nice to depend on less frameworks, and it would make the code more portable if/when I decide to port SMServer to Mac, but I don't know if those small benefits are enough to merit the time/energy that would be needed to port everything over. What are your thoughts? |
Unfortunately, I don't know enough about the differences in the frameworks to give a substantial answer. However, I do know that SMServer works, and it works very well. I also know what it's like to work on something for months and then have that silent "Ohh😬" moment when you realize that a redesign or reworking is possible/would be better. The benefits of depending solely on IMCore instead of ChatKit as I see them are
But now, the drawbacks. You said that you're not sure if the benefits merit the time and energy required for a rewrite/port, and I agree. You're one person working on this tweak and it's a lot for you to undertake. In an ideal situation, a team of jailbreak and iMessage forwarding devs teams up to do this rewrite together, and people like me who are enthusiastic about the app either learn more programming to help as well or we donate to the project. But as it stands now, you'd have to do this mostly on your own, so here are a few cons.
That's about all I have right now, I may edit this comment to add or remove things, or just make new comments. Let me know what you think. |
Sending attachments using IMCore uses the following process (on macOS):
+(IMFileTransfer *) prepareFileTransferForAttachment:(NSURL *) originalPath filename:(NSString *) filename {
// Creates the initial guid for the file transfer (cannot use for sending)
NSString *transferInitGuid = [[IMFileTransferCenter sharedInstance] guidForNewOutgoingTransferWithLocalURL:originalPath useLegacyGuid:YES];
// Creates the initial transfer object
IMFileTransfer *newTransfer = [[IMFileTransferCenter sharedInstance] transferForGUID:transferInitGuid];
// Get location of where attachments should be placed
NSString *persistentPath = [[IMDPersistentAttachmentController sharedInstance] _persistentPathForTransfer:newTransfer filename:filename highQuality:TRUE chatGUID:nil storeAtExternalPath:TRUE];
if (persistentPath) {
NSError *folder_creation_error;
NSError *file_move_error;
NSURL *persistentURL = [NSURL fileURLWithPath:persistentPath];
// Create the attachment location
[[NSFileManager defaultManager] createDirectoryAtURL:[persistentURL URLByDeletingLastPathComponent] withIntermediateDirectories:TRUE attributes:nil error:&folder_creation_error];
// Handle error and exit
if (folder_creation_error) {
return nil;
}
// Copy the file to the attachment location
[[NSFileManager defaultManager] copyItemAtURL:originalPath toURL:persistentURL error:&file_move_error];
// Handle error and exit
if (file_move_error) {
return nil;
}
// We updated the transfer location
[[IMFileTransferCenter sharedInstance] retargetTransfer:[newTransfer guid] toPath:persistentPath];
// Update the local url inside of the transfer
newTransfer.localURL = persistentURL;
}
// Register the transfer (The file must be in correct location before this)
// *Warning* Can fail but gives only warning in console that failed
[[IMFileTransferCenter sharedInstance] registerTransferWithDaemon:[newTransfer guid]];
return newTransfer;
}
NSMutableAttributedString *attachmentStr = [[NSMutableAttributedString alloc] initWithString: @"\ufffc"];
[attachmentStr addAttributes:@{
@"__kIMBaseWritingDirectionAttributeName": @"-1",
@"__kIMFileTransferGUIDAttributeName": fileTransfer.guid,
@"__kIMFilenameAttributeName": [fileUrl lastPathComponent],
@"__kIMMessagePartAttributeName": @0,
} range:NSMakeRange(0, 1)]; "\ufffc" is an object replacement character which iMessage uses to denote an attachment.
|
I was reading here and saw that the a limitation of sending messages through IMCore was that there was no way to send attachments. I asked Eric from MyMessage about this, and he pointed me to this page. Would it be possible to have SMServer fully integrate with IMCore? Or would ChatKit still be needed for certain functions?
The text was updated successfully, but these errors were encountered: