When sharing text from an app on IOS 9.2 you can choose from various messagin options. The problem is that most options like mail or sms expect \n
to be the line break while WhatsApp expects <BR>
to be the line break.
I'm told that there is no way to know in the app what the user will choose so I'm sending \n<BR>
. While is works well for WhatsApp that ignores the \n
it does not work well for Mail that shows the <BR>
.
Also tried %0A%0D
but WhatsAPP ignores.
EDIT
As of 2017-07-19, WhatsApp for iOS no longer interprets <br>
as newline, and instead switched to \n
.
This isn't a backwards compatible change, so if you use <br>
you will literally get Some<br>Text
. The code below should no longer be used; the good news is that you don't need to do nothing: WhatsApp will handle \n
like it always should have.
DEPRECATED
I used my own UIActivityItemProvider
which, depending on the chosen activity, uses \n
or <br>
:
@interface ShareManager : UIActivityItemProvider <UIActivityItemSource>
@end
@implementation ShareManager
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
id result = [self getShareText];
if ([activityType containsIgnoringCase:@"WhatsApp"]) // You can also match against the exact id "net.whatsapp.WhatsApp.ShareExtension"
{
result = [result stringByReplacingOccurrencesOfString:@"\n" withString:@"<br>"];
}
return result;
}
@end
Usage:
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:@[[[ShareManager alloc] init]]];
[self presentViewController:activity animated:YES completion:nil];