Studyplus iOS SDK for Objective-C。 新的 Studyplus iOS SDK for Swift。
git clone https://github.com/studyplus/Studyplus-iOS-SDK
或从 此页面 下载 zip 文件。build/Release/deliverables/StudyplusSDK
拷贝到您的项目中。Security.framework, SystemConfiguration.framework, MobileCoreServices, CoreGraphics
等)。请参阅 AFNetworking 和 UICKeyChainStore。git clone https://github.com/studyplus/Studyplus-iOS-SDK
或从 此页面 下载 zip 文件。将 "studyplus-{your consumer key}" 设置为 URL 类型。 (例如:studyplus-MIoh79q7pfMbTUVA3BNsSeTaZRcOK3yg )
#import "SPLStudyplusDelegate.h"
@interface YourClass<SPLStudyplusDelegate>
-(BOOL)openURL:(NSURL*)url;
@end
#import "SPLStudyplus.h"
static NSString * const ConsumerKey = @"Your Studyplus consumer key";
static NSString * const ConsumerSecret = @"Your Studyplus consumer secret";
static SPLStudyplus *studyplus;
@implementation YourClass
-(id) init {
if (self = [super init]) {
studyplus = [SPLStudyplus studyplusWithConsumerKey:ConsumerKey
andConsumerSecret:ConsumerSecret];
studyplus.delegate = self;
}
return self;
}
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [yourClassObject openURL:url];
}
@interface YourClass
-(BOOL)openURL:(NSURL*)url;
@end
@implementation YourClass
-(void) doAuth {
[studyplus auth];
}
-(void) doLogin
{
[studyplus login];
}
// Called by AppDelegate
-(BOOL) openURL:(NSURL*)url
{
return [studyplus openURL:url];
}
// callback methods
-(void)studyplusDidConnect:(SPLStudyplus*)studyplus
{
NSLog(@"Auth or Login succeeded");
}
-(void)studyplusDidFailToConnect:(SPLStudyplus*)studyplus withError:(NSError*)error
{
NSLog(@"Auth or Login failed");
}
- (void)studyplusDidCancel:(SPLStudyplus*)studyplus
{
NSLog(@"Auth or Login canceled");
}
-(void)post
{
// Create new study record.
SPLStudyplusRecord *studyplusRecord =
[SPLStudyplusRecord
/**
@see SPLStopwatch
*/
recordWithDuration:[studyplus.stopwatch elapsedSeconds]
/** You can add optional info.
options:@{
// Time the learning is ended. 学習を終えた日時。
@"recordedAt" : [NSDate date],
// Studyplus timeline comment. Studyplusのタイムライン上で表示されるコメント。
@"comment" : @"アプリ◯◯で勉強しました!!",
// @see SPLStudyplusRecordAmount
@"amount" : [SPLStudyplusRecordAmount amount:100],
}
*/
];
// post
[studyplus postStudyRecord:studyplusRecord];
}
// callback methods
-(void)studyplusDidPostStudyRecord:(SPLStudyplus*)studyplus
{
NSLog(@"Post to Studyplus succeeded");
}
-(void)studyplusDidFailToPostStudyRecord:(SPLStudyplus*)studyplus withError:(NSError*)error
{
// see @SPLStudyplusError with error.code.
NSLog(@"Post to Studyplus failed");
}
pod try StudyplusSDK
或查看示例目录并打开 StudyplusSDKDemo/StudyplusSDKDemo.xcodeproj