TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2015 |
Maintained by Yeung Yiu Hung.
SocialLib is available through CocoaPods. To install it, simply add the following line to your Podfile:
Install all platform (Facebook, Twitter, Tumblr, Instagram, Weibo and Weixin)
pod 'SocialLib'
For specific social platform, use subspec
pod 'SocialLib/Facebook'
pod 'SocialLib/Twitter'
pod 'SocialLib/Tumblr'
pod 'SocialLib/Instagram'
pod 'SocialLib/Weibo'
pod 'SocialLib/Weixin'
In your .pch, add following lines
//Facebook:
#import <SocialLib/SocialLib+Facebook.h>
//Twitter:
#import <SocialLib/SocialLib+Twitter.h>
//Tumblr:
#import <SocialLib/SocialLib+Tumblr.h>
//Weibo:
#import <SocialLib/SocialLib+Weibo.h>
//Weixin / WeChat:
#import <SocialLib/SocialLib+Weixin.h>
In your AppDelegate,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return [SocialLib connectSocialPlatformWithApplication:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[SocialLib applicationDidBecomeActie:application];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [SocialLib handleOpenURL:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
(<dict>...</dict>)
.<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{FACEBOOK_APP_ID}</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>{FACEBOOK_APP_ID}</string>
<key>FacebookDisplayName</key>
<string>{Your App Name}</string>
For iOS 9
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSExceptionRequiresForwardSecrecy</key> <false/>
</dict>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
(<key>CFBundleURLTypes</key>
<array>...</array>)
.Replace {URL Scheme} to what you want:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>{URL Scheme}</string>
</array>
</dict>
(<dict>...</dict>)
Replace:
<key>TwitterCallbackURL</key>
<string>{URL Scheme}</string>
<key>TwitterConsumerKey</key>
<string>{Twitter Consumer Key}</string>
<key>TwitterConsumerSecret</key>
<string>{Twitter Consumer Secret}</string>
For Twitter application, you must have a valid callback url, otherwise the sharing will not work.
(<key>CFBundleURLTypes</key>
<array>...</array>)
.Replace {URL Scheme} to what you want, must be unique:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>{URL Scheme}</string>
</array>
</dict>
Add following lines into body of your file (<dict>...</dict>)
Replace:
<key>TumblrCallbackURL</key>
<string>{URL Scheme}</string>
<key>TumblrConsumerKey</key>
<string>{Tumblr Consumer Key}</string>
<key>TumblrConsumerSecret</key>
<string>{Tumblr Consumer Secret}</string>
(<key>CFBundleURLTypes</key>
<array>...</array>)
.Replace {WEIBO API ID} with your Weibo App ID:
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.weibo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{WEIBO API ID}</string>
</array>
</dict>
Add following lines into body of your file (<dict>...</dict>)
Replace:
<key>WeiboAppID</key>
<string>{WEIBO API ID}</string>
(<key>CFBundleURLTypes</key>
<array>...</array>)
.Replace {WEIXIN API ID} with your Weixin App ID:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>{WEIXIN API ID}</string>
</array>
</dict>
Add following lines into body of your file (<dict>...</dict>)
Replace:
<key>WeixinAppID</key>
<string>ENTER{WEIXIN API ID}</string>
<key>WeixinAppName</key>
<string>{WEIXIN API NAME}</string>
To run the example project, clone the repo, and run pod install
from the Example directory first.
Demo provided Facebook, Twitter and Tumblr api keys, Weibo and Weixin api keys are empty
You need a modal object to use SocialLib share
InfoModal.h
#import <Foundation/Foundation.h>
@interface InfoModal : NSObject <SocialLibFacebookMessage, SocialLibTwitterMessage, SocialLibTumblrMessage, SocialLibWeiboMessage, SocialLibWeixinMessage>{
}
@property (nonatomic, strong) NSString *infoTitle;
@property (nonatomic, strong) NSString *infoContent;
@property (nonatomic, strong) NSString *infoContentURL;
@property (nonatomic, strong) NSArray *infoImages;
@property (nonatomic, strong) NSString *infoThumbnailImageURL;
@property (nonatomic, strong) NSString *infoVideoURL;
InfoModal.m
#import "InfoModal.h"
@implementation InfoModal
#pragma mark - SocialLibMessage
- (NSString *)title{
return _infoTitle;
}
- (NSString *)content{
return _infoContent;
}
- (NSString *)contentURL{
return _infoContentURL;
}
- (NSArray *)images{
return _infoImages;
}
- (NSString *)thumbnailImageURL{
return _infoThumbnailImageURL;
}
- (NSString *)videoURL{
return _infoVideoURL;
}
- (NSString *)tweetContent{
return [NSString stringWithFormat:@"%@ - %@ %@",_infoTitle, _infoContent, _infoContentURL];
}
- (SocialLibTwitterMessageType)twitterMessageType{
return SocialLibTwitterMessageTypeText;
}
- (SocialLibTumblrMessageType)tumblrMessageType{
return SocialLibTumblrMessageTypeLink;
}
- (SocialLibWeiboMessageType)weiboMessageType{
return SocialLibWeiboMessageTypeText;
}
- (SocialLibWeixinMessageType)weixinMessageType{
return SocialLibWeixinMessageTypeLink;
}
@end
To share facebook use
InfoModal *info = [[InfoModal alloc] init];
info.infoTitle = @"SocialLib";
info.infoContent = @"Share via SocialLib";
info.infoContentURL = @"http://darkcl.github.io/SocialLib";
[SocialLib shareModal:info
toPlatform:kSocialLibPlatformFacebook
success:^(NSDictionary *message) {
NSLog(@"%@", message);
}
failure:^(NSDictionary *message, NSError *error) {
NSLog(@"%@", error);
}];
To share twitter use
InfoModal *info = [[InfoModal alloc] init];
info.infoTitle = @"SocialLib";
info.infoContent = @"Share via SocialLib";
info.infoContentURL = @"http://darkcl.github.io/SocialLib";
[SocialLib shareModal:info
toPlatform:kSocialLibPlatformTwitter
success:^(NSDictionary *message) {
NSLog(@"%@", message);
}
failure:^(NSDictionary *message, NSError *error) {
NSLog(@"%@", error);
}];
Yeung Yiu Hung, [email protected]
SocialLib is available under the MIT license. See the LICENSE file for more info.