测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2017年10月 |
由 WUBOSS 维护。
依赖关系 | |
WeexPluginLoader | >= 0 |
WeexSDK | >= 0 |
weex-aliPush 是一个用于 weex 的 ali 推送插件,可以通过 weexpack 快速集成,可以丰富 weex 的功能
支持的 weexpack 版本: >= 0.2.0
支持的 WeexSDK 版本: >= 0.10.0
weexpack create weextest
weexpack platform add ios
weexpack platform add android
weexpack plugin add weex-aliPush
[github](请添加您源代码的地址)
命令行集成
weexpack plugin add weex-aliPush
手动集成
在 podfile 中添加
pod 'WeexAliPush'
api
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[CloudPushSDK asyncInit:@"" appSecret:@"" callback:^(CloudPushCallbackResult *res) {
if (res.success) {
NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
} else {
NSLog(@"Push SDK init failed, error: %@", res.error);
}
}];
[CloudPushSDK sendNotificationAck:launchOptions];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMessageReceived:)
name:@"CCPDidReceiveMessageNotification"
object:nil];
[self registerRemoteNotification];
return YES;
}
- (void)onMessageReceived:(NSNotification *)notification {
}
- (void)registerRemoteNotification {
/*
警告:Xcode8 需要手动开启"TARGETS -> Capabilities -> Push Notifications"
*/
/*
警告:该方法需要开发者自定义,以下代码根据 APP 支持的 iOS 系统不同,代码可以对应修改。
以下为演示代码,注意根据实际需要修改,注意测试支持的 iOS 系统都能获取到 DeviceToken
*/
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
}
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#else // Xcode 7编译会调用
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#endif
} else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeBadge);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// 将收到的APNs信息传给个推统计
[CloudPushSDK sendNotificationAck:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler {
[CloudPushSDK sendNotificationAck:response.notification.request.content.userInfo];
completionHandler();
}
const plugin = weex.requireModule('weexAliPush');
// 收到通知
plugin.receiveNotification(function(ret){
});
// 收到消息
plugin.receiveAlimessage(function(ret){
});
// 通知点击
plugin.notifacationClick(function(ret){
});