-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/AndyDentFree/im-plausibil…
…ities * 'master' of https://github.com/AndyDentFree/im-plausibilities: readme update imUrlDatAppSUI - Fix app sender and include refactoring from imUrlDataApp (still broken) MessagesViewController.swift - Mood enum moved out to its own file - local let moodKey moved to Mood enum - Mood subscript added imUrlDataApp renamed MessageComposingHelper file to match class imUrlDataApp - Fix app sender to send last-tapped emoji (was always "happy") MessagesViewController.swift - Mood enum moved out to its own file - local let moodKey moved to Mood enum - subscript added imUrlDataApp - Refactor Message Sending from App for easy reuse in other sample ViewController.swift - var messager added - displayMessageInterface and messageComposeViewController moved to MessageComposerInApp - viewDidLoad use messager to set state if !canSendText - onAppSendButton call messager to display imUrlDataAppSUI - Adding Messenger extension Target showing SwiftUI Adding Messenger extension Target imUrlDataAppSUI IM project target added as iMessage extension
- Loading branch information
Showing
23 changed files
with
1,190 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 82 additions & 66 deletions
148
imStickered/imStickered MessagesExtension/Base.lproj/MainInterface.storyboard
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Mood.swift | ||
// imUrlDataApp | ||
// | ||
// Created by AndyDent on 6/8/2022. | ||
// Copyright © 2022 Touchgram Pty Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum Mood : String, CaseIterable { | ||
case happy | ||
case quizzical | ||
case distraught | ||
case angry | ||
|
||
static let moodKey = "mood" | ||
|
||
static subscript(i: Int) -> Mood? { | ||
guard i >= 0 && i < 4 else {return nil} | ||
return Mood.allCases[i] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// MessageComposerInApp.swift | ||
// imUrlDataApp | ||
// | ||
// Created by AndyDent on 5/8/2022. | ||
// Copyright © 2022 Touchgram Pty Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MessageUI | ||
import Messages | ||
|
||
class MessageComposingHelper: NSObject, MFMessageComposeViewControllerDelegate { | ||
|
||
func canSendText() -> Bool { | ||
MFMessageComposeViewController.canSendText() | ||
} | ||
|
||
func displayMessageInterface(onVC vc: UIViewController, mood:Mood) { | ||
let composeVC = MFMessageComposeViewController() | ||
composeVC.messageComposeDelegate = self | ||
|
||
// Configure the fields of the interface. | ||
composeVC.recipients = ["123456"] | ||
composeVC.body = "Sending a custom message" | ||
// | ||
/* | ||
According to | ||
https://developer.apple.com/documentation/messageui/mfmessagecomposeviewcontroller/2213331-message | ||
If your app has an iMessage app extension, you can display your iMessage app within the message compose view, just as you would in the Messages app. To display your iMessage app, create and assign an MSMessage object to this property. | ||
|
||
By default, this property is set to nil. | ||
*/ | ||
if #available(iOS 10, *) { // necessary if clause to make XCode happy to use composeVC.message | ||
let message = MSMessage(session: MSSession()) | ||
// fake building a smiley using hardcoded stuff to match MessagesViewController.send | ||
guard var urlComps = URLComponents(string:"data:,") else { | ||
fatalError("Invalid base URL") | ||
} | ||
urlComps.queryItems = [URLQueryItem(name: Mood.moodKey, value:mood.rawValue)] | ||
message.url = urlComps.url | ||
composeVC.message = message | ||
} | ||
|
||
// Present the view controller modally. | ||
if MFMessageComposeViewController.canSendText() { | ||
vc.present(composeVC, animated: true, completion: nil) | ||
} else { | ||
print("Can't send messages.") | ||
} | ||
} | ||
|
||
//MARK - conform to MFMessageComposeViewControllerDelegate | ||
func messageComposeViewController(_ controller: MFMessageComposeViewController, | ||
didFinishWith result: MessageComposeResult) { | ||
// Check the result or perform other tasks. | ||
let msgStr = result == .cancelled ? | ||
"Cancelled" : result == .failed ? | ||
"Failed" : | ||
"Sent" | ||
print(msgStr) | ||
// Dismiss the message compose view controller. | ||
controller.dismiss(animated: true, completion: nil) | ||
} | ||
} |
Oops, something went wrong.