forked from ideashower/ShareKit
-
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.
Added text message capabilities for SMS messages.
Share Text Message through Text button to launch Messages on iOS4 only.
- Loading branch information
1 parent
f6aac65
commit 554eea6
Showing
3 changed files
with
219 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
Classes/ShareKit/Sharers/Actions/Text Message/SHKTextMessage.h
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,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
179
Classes/ShareKit/Sharers/Actions/Text Message/SHKTextMessage.m
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,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 |