| 1 |
/* |
| 2 |
Copyright 2017-2017 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in the "Castle Game Engine" distribution, |
| 8 |
for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
*/ |
| 16 |
|
| 17 |
/* Service to handle miscellaneous simple messages, like view URLs. */ |
| 18 |
|
| 19 |
#import "MiscellaneousService.h" |
| 20 |
|
| 21 |
@implementation MiscellaneousService |
| 22 |
|
| 23 |
- (void)viewUrl:(NSString*) url |
| 24 |
{ |
| 25 |
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]]; |
| 26 |
} |
| 27 |
|
| 28 |
- (void)openApplicationStore:(NSString*) applicationId |
| 29 |
{ |
| 30 |
// see https://stackoverflow.com/questions/3124080/app-store-link-for-rate-review-this-app |
| 31 |
|
| 32 |
static NSString *const iOS7AppStoreURLFormat = @"itms-apps://itunes.apple.com/app/id%@"; |
| 33 |
static NSString *const iOSAppStoreURLFormat = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@"; |
| 34 |
|
| 35 |
NSString* url = [NSString stringWithFormat: |
| 36 |
([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f) ? |
| 37 |
iOS7AppStoreURLFormat : iOSAppStoreURLFormat, applicationId]; |
| 38 |
|
| 39 |
[self viewUrl: url]; |
| 40 |
} |
| 41 |
|
| 42 |
- (void)shareText:(NSString*) title |
| 43 |
subject:(NSString*) subject |
| 44 |
content:(NSString*) content |
| 45 |
{ |
| 46 |
// see https://stackoverflow.com/questions/25320520/sharing-text-as-a-string-to-another-app |
| 47 |
|
| 48 |
UIActivityViewController *activityVC = [[UIActivityViewController alloc] |
| 49 |
initWithActivityItems: @[content] applicationActivities: nil]; |
| 50 |
activityVC.excludedActivityTypes = @[ |
| 51 |
UIActivityTypePrint, |
| 52 |
UIActivityTypeCopyToPasteboard, |
| 53 |
UIActivityTypeAssignToContact, |
| 54 |
UIActivityTypeSaveToCameraRoll]; // Exclude whichever aren't relevant |
| 55 |
[self.mainController presentViewController: activityVC animated: YES completion: nil]; |
| 56 |
} |
| 57 |
|
| 58 |
- (bool)messageReceived:(NSArray* )message |
| 59 |
{ |
| 60 |
if (message.count == 2 && |
| 61 |
[[message objectAtIndex: 0] isEqualToString:@"view-url"]) |
| 62 |
{ |
| 63 |
[self viewUrl: [message objectAtIndex: 1]]; |
| 64 |
return TRUE; |
| 65 |
} else |
| 66 |
if (message.count == 2 && |
| 67 |
[[message objectAtIndex: 0] isEqualToString:@"open-application-store"]) |
| 68 |
{ |
| 69 |
[self openApplicationStore: [message objectAtIndex: 1]]; |
| 70 |
return TRUE; |
| 71 |
} else |
| 72 |
if (message.count == 4 && |
| 73 |
[[message objectAtIndex: 0] isEqualToString:@"share-text"]) |
| 74 |
{ |
| 75 |
[self shareText: [message objectAtIndex: 1] |
| 76 |
subject: [message objectAtIndex: 2] |
| 77 |
content: [message objectAtIndex: 3]]; |
| 78 |
return TRUE; |
| 79 |
} |
| 80 |
|
| 81 |
return FALSE; |
| 82 |
} |
| 83 |
|
| 84 |
@end |