Skip to content

Commit

Permalink
Added text message capabilities for SMS messages.
Browse files Browse the repository at this point in the history
Share Text Message through Text button to launch
Messages on iOS4 only.
  • Loading branch information
maarek authored and ideashower committed Nov 15, 2010
1 parent f6aac65 commit 554eea6
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 0 deletions.
1 change: 1 addition & 0 deletions Classes/ShareKit/Core/SHKSharers.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string>SHKPhotoAlbum</string>
<string>SHKCopy</string>
<string>SHKMail</string>
<string>SHKTextMessage</string>
<string>SHKSafari</string>
</array>
<key>services</key>
Expand Down
39 changes: 39 additions & 0 deletions Classes/ShareKit/Sharers/Actions/Text Message/SHKTextMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SHKTextMessage.h
// ShareKit
//
// Created by Jeremy Lyman on 9/21/10.

//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>
#import "SHKSharer.h"

@interface SHKTextMessage : SHKSharer <MFMessageComposeViewControllerDelegate>
{

}

- (BOOL)sendText;

@end
179 changes: 179 additions & 0 deletions Classes/ShareKit/Sharers/Actions/Text Message/SHKTextMessage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//
// SHKTextMessage.m
// ShareKit
//
// Created by Jeremy Lyman on 9/21/10.

//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

#import "SHKTextMessage.h"


@implementation MFMessageComposeViewController (SHK)

- (void)SHKviewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];

// Remove the SHK view wrapper from the window
[[SHK currentHelper] viewWasDismissed];
}

@end



@implementation SHKTextMessage

#pragma mark -
#pragma mark Configuration : Service Defination

+ (NSString *)sharerTitle
{
return @"Text";
}

+ (BOOL)canShareText
{
return YES;
}

+ (BOOL)canShareURL
{
return YES;
}

+ (BOOL)canShareImage
{
return NO;
}

+ (BOOL)canShareFile
{
return NO;
}

+ (BOOL)shareRequiresInternetConnection
{
return NO;
}

+ (BOOL)requiresAuthentication
{
return NO;
}


#pragma mark -
#pragma mark Configuration : Dynamic Enable

+ (BOOL)canShare
{
return [MFMessageComposeViewController canSendText];
}

- (BOOL)shouldAutoShare
{
return YES;
}



#pragma mark -
#pragma mark Share API Methods

- (BOOL)send
{
self.quiet = YES;

if (![self validateItem])
return NO;

return [self sendText]; // Put the actual sending action in another method to make subclassing SHKTextMessage easier
}

- (BOOL)sendText
{
MFMessageComposeViewController *composeView = [[[MFMessageComposeViewController alloc] init] autorelease];
composeView.messageComposeDelegate = self;

NSString * body = [item customValueForKey:@"body"];

if (!body) {
if (item.text != nil)
body = item.text;

if (item.URL != nil)
{
NSString *urlStr = [item.URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

if (body != nil)
body = [body stringByAppendingFormat:@"<br/><br/>%@", urlStr];

else
body = urlStr;
}

// fallback
if (body == nil)
body = @"";

// sig
if (SHKSharedWithSignature)
{
body = [body stringByAppendingString:@"<br/><br/>"];
body = [body stringByAppendingString:SHKLocalizedString(@"Sent from %@", SHKMyAppName)];
}

// save changes to body
[item setCustomValue:body forKey:@"body"];
}

[composeView setBody:body];
[[SHK currentHelper] showViewController:composeView];

return YES;
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {

[[SHK currentHelper] hideCurrentViewControllerAnimated:YES];

switch (result)
{
case MessageComposeResultCancelled:
[self sendDidCancel];
break;
case MessageComposeResultSent:
[self sendDidFinish];
break;
case MessageComposeResultFailed:
[self sendDidFailWithError:nil];
break;
default:
break;
}
}


@end

0 comments on commit 554eea6

Please sign in to comment.