Browse Source

增加ios项目

a289459798 8 years ago
parent
commit
5300551235

+ 134 - 2
README.md

@@ -1,6 +1,8 @@
 # react-native-mipush
 
-[TOC]
+该项目基于小米推送,使用前,请先在小米开发者后台注册app,并获取对应的appid与appkey。
+
+开发环信:xcode8、react-native 0.35
 
 ##安装
 
@@ -54,12 +56,110 @@ protected List<ReactPackage> getPackages() {
 
 ##ios
 
-==正在开发,待更新==
+==必须通过xcode8开发的项目==
+
+ios需要先制作推送证书,具体教程请自行百度。
+
+本项目是基于`RCTPushNotification`,请将RCTPushNotification拖动到`Libraries`目录下。
+
+添加所需依赖库:
+- UserNotifications.framework
+- libresolv.dylib(tbd)
+- libxml2.dylib(tbd)
+- libz.dylib(tbd)
+- SystemConfiguration.framework
+- MobileCoreServices.framework
+- CFNetwork.framework
+- CoreTelephony.framework
+
+在`target`的`Capabilities`选项卡打开`Push Notifications`
+
+在`target`的`Build Phases`选项卡添加`Link Binary With Libraries`:
+
+> libRCTPushNotification.a
+> libRCTMIPushModule.a
+
+在targets->Build Settings下面搜索 Header Search Paths,添加
+
+> $(SRCROOT)/../node_modules/react-native-mipush/ios/MIPushModule
+>
+> $(SRCROOT)/../node_modules/react-native/Libraries/PushNotificationIOS
+
+设置为 `recursive`
+
+打开工程下`Info.plist`文件为源代码形式打开,添加以下信息:
+
+```
+<key>MiSDKAppID</key>
+<string>1000888</string>
+<key>MiSDKAppKey</key>
+<string>500088888888</string>
+<key>MiSDKRun</key>
+<string>Online</string>
+```
+
+修改 AppDelegate.m 文件:
+
+```
+...
+#import "MIPushModule.h"
+#import "RCTPushNotificationManager.h"
+...
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+	...
+  	[MIPushModule application:application didFinishLaunchingWithOptions:launchOptions];
+    ...
+}
+
+- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
+{
+
+  [MIPushModule application:application didRegisterUserNotificationSettings:notificationSettings];
+  ...
+}
+
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
+{
+  [MIPushModule application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+  ...
+}
+
+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
+{
+  [MIPushModule application:application didReceiveRemoteNotification:notification];
+  ...
+}
+
+- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+  [MIPushModule application:application didReceiveLocalNotification:notification];
+  ...
+}
+
+// ios 10
+// 应用在前台收到通知
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
+  [MIPushModule userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
+  ...
+}
+
+// 点击通知进入应用
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
+  [MIPushModule userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+  ....
+  completionHandler();
+}
+
+```
+
 
 ##RN中使用
 
 Demo:
 
+**android**
+
 ```
 ...
 
@@ -96,6 +196,38 @@ componentDidMount() {
   }
 ```
 
+**ios**
+
+```
+...
+componentWillUnmount() {
+
+    MIPush.unsetAlias("bbbbbb");
+    MIPush.removeEventListener("notification");
+  }
+
+  componentDidMount() {
+
+    MIPush.setAlias("bbbbbb");
+
+	MIPush.setBadgeNumber(0);   // 每次进入app将角标设置为0
+    MIPush.addEventListener("notification", (notification) => {
+
+      console.log("app接收到通知:", notification);
+      
+      // 弹出确认框
+    });
+
+    MIPush.getInitialNotification((notification) => {
+
+      console.log("app关闭时获取点击通知消息:", notification);
+	  // 弹出确认框
+    });
+
+  }
+  ...
+```
+
 暂支持的所有方法:
 
 ```

+ 3 - 3
index.js

@@ -7,11 +7,11 @@
 import {
     NativeModules,
     Platform,
-    PushNotificationIOS
+    PushNotificationIOS,
+    NativeEventEmitter
 } from 'react-native';
 
-const NativeEventEmitter = require('NativeEventEmitter');
-var MIPushModule = NativeModules.MIPushModule;
+const MIPushModule = NativeModules.MIPushModule;
 
 /**
  * 获取app的版本名称\版本号和渠道名

+ 288 - 0
ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.pbxproj

@@ -0,0 +1,288 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 46;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		2BC4EF001DBDFDDD00715730 /* RCTMIPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BC4EEFF1DBDFDDD00715730 /* RCTMIPushModule.m */; };
+		2BC4EF011DBDFDDD00715730 /* RCTMIPushModule.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2BC4EEFE1DBDFDDD00715730 /* RCTMIPushModule.h */; };
+		2BC4EF091DBDFE3700715730 /* libMiPushSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BC4EF071DBDFE3700715730 /* libMiPushSDK.a */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+		2BC4EEF91DBDFDDD00715730 /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = "include/$(PRODUCT_NAME)";
+			dstSubfolderSpec = 16;
+			files = (
+				2BC4EF011DBDFDDD00715730 /* RCTMIPushModule.h in CopyFiles */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+		2BC4EEFB1DBDFDDD00715730 /* libRCTMIPushModule.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTMIPushModule.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		2BC4EEFE1DBDFDDD00715730 /* RCTMIPushModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTMIPushModule.h; sourceTree = "<group>"; };
+		2BC4EEFF1DBDFDDD00715730 /* RCTMIPushModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTMIPushModule.m; sourceTree = "<group>"; };
+		2BC4EF071DBDFE3700715730 /* libMiPushSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMiPushSDK.a; sourceTree = "<group>"; };
+		2BC4EF081DBDFE3700715730 /* MiPushSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MiPushSDK.h; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		2BC4EEF81DBDFDDD00715730 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				2BC4EF091DBDFE3700715730 /* libMiPushSDK.a in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		2BC4EEF21DBDFDDD00715730 = {
+			isa = PBXGroup;
+			children = (
+				2BC4EEFD1DBDFDDD00715730 /* RCTMIPushModule */,
+				2BC4EEFC1DBDFDDD00715730 /* Products */,
+			);
+			sourceTree = "<group>";
+		};
+		2BC4EEFC1DBDFDDD00715730 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				2BC4EEFB1DBDFDDD00715730 /* libRCTMIPushModule.a */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		2BC4EEFD1DBDFDDD00715730 /* RCTMIPushModule */ = {
+			isa = PBXGroup;
+			children = (
+				2BC4EF071DBDFE3700715730 /* libMiPushSDK.a */,
+				2BC4EF081DBDFE3700715730 /* MiPushSDK.h */,
+				2BC4EEFE1DBDFDDD00715730 /* RCTMIPushModule.h */,
+				2BC4EEFF1DBDFDDD00715730 /* RCTMIPushModule.m */,
+			);
+			path = RCTMIPushModule;
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+		2BC4EEFA1DBDFDDD00715730 /* RCTMIPushModule */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 2BC4EF041DBDFDDD00715730 /* Build configuration list for PBXNativeTarget "RCTMIPushModule" */;
+			buildPhases = (
+				2BC4EEF71DBDFDDD00715730 /* Sources */,
+				2BC4EEF81DBDFDDD00715730 /* Frameworks */,
+				2BC4EEF91DBDFDDD00715730 /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = RCTMIPushModule;
+			productName = RCTMIPushModule;
+			productReference = 2BC4EEFB1DBDFDDD00715730 /* libRCTMIPushModule.a */;
+			productType = "com.apple.product-type.library.static";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		2BC4EEF31DBDFDDD00715730 /* Project object */ = {
+			isa = PBXProject;
+			attributes = {
+				LastUpgradeCheck = 0800;
+				ORGANIZATIONNAME = zzy;
+				TargetAttributes = {
+					2BC4EEFA1DBDFDDD00715730 = {
+						CreatedOnToolsVersion = 8.0;
+						DevelopmentTeam = 33KGZ49A6U;
+						ProvisioningStyle = Automatic;
+					};
+				};
+			};
+			buildConfigurationList = 2BC4EEF61DBDFDDD00715730 /* Build configuration list for PBXProject "RCTMIPushModule" */;
+			compatibilityVersion = "Xcode 3.2";
+			developmentRegion = English;
+			hasScannedForEncodings = 0;
+			knownRegions = (
+				en,
+			);
+			mainGroup = 2BC4EEF21DBDFDDD00715730;
+			productRefGroup = 2BC4EEFC1DBDFDDD00715730 /* Products */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				2BC4EEFA1DBDFDDD00715730 /* RCTMIPushModule */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+		2BC4EEF71DBDFDDD00715730 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				2BC4EF001DBDFDDD00715730 /* RCTMIPushModule.m in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+		2BC4EF021DBDFDDD00715730 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INFINITE_RECURSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_SUSPICIOUS_MOVES = YES;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+				COPY_PHASE_STRIP = NO;
+				DEBUG_INFORMATION_FORMAT = dwarf;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				ENABLE_TESTABILITY = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+				MTL_ENABLE_DEBUG_INFO = YES;
+				ONLY_ACTIVE_ARCH = YES;
+				SDKROOT = iphoneos;
+			};
+			name = Debug;
+		};
+		2BC4EF031DBDFDDD00715730 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INFINITE_RECURSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_SUSPICIOUS_MOVES = YES;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+				COPY_PHASE_STRIP = NO;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				ENABLE_NS_ASSERTIONS = NO;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+				MTL_ENABLE_DEBUG_INFO = NO;
+				SDKROOT = iphoneos;
+				VALIDATE_PRODUCT = YES;
+			};
+			name = Release;
+		};
+		2BC4EF051DBDFDDD00715730 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DEVELOPMENT_TEAM = 33KGZ49A6U;
+				HEADER_SEARCH_PATHS = (
+					"$(SRCROOT)/../../../react-native/React/**",
+					"$(SRCROOT)/../../../react-native/Libraries/PushNotificationIOS",
+				);
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/RCTMIPushModule",
+				);
+				OTHER_LDFLAGS = "-ObjC";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SKIP_INSTALL = YES;
+			};
+			name = Debug;
+		};
+		2BC4EF061DBDFDDD00715730 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DEVELOPMENT_TEAM = 33KGZ49A6U;
+				HEADER_SEARCH_PATHS = (
+					"$(SRCROOT)/../../../react-native/React/**",
+					"$(SRCROOT)/../../../react-native/Libraries/PushNotificationIOS",
+				);
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/RCTMIPushModule",
+				);
+				OTHER_LDFLAGS = "-ObjC";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SKIP_INSTALL = YES;
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		2BC4EEF61DBDFDDD00715730 /* Build configuration list for PBXProject "RCTMIPushModule" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				2BC4EF021DBDFDDD00715730 /* Debug */,
+				2BC4EF031DBDFDDD00715730 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		2BC4EF041DBDFDDD00715730 /* Build configuration list for PBXNativeTarget "RCTMIPushModule" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				2BC4EF051DBDFDDD00715730 /* Debug */,
+				2BC4EF061DBDFDDD00715730 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 2BC4EEF31DBDFDDD00715730 /* Project object */;
+}

+ 7 - 0
ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:RCTMIPushModule.xcodeproj">
+   </FileRef>
+</Workspace>

BIN
ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.xcworkspace/xcuserdata/zhangzy.xcuserdatad/UserInterfaceState.xcuserstate


+ 80 - 0
ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/RCTMIPushModule.xcscheme

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0800"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "2BC4EEFA1DBDFDDD00715730"
+               BuildableName = "libRCTMIPushModule.a"
+               BlueprintName = "RCTMIPushModule"
+               ReferencedContainer = "container:RCTMIPushModule.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "2BC4EEFA1DBDFDDD00715730"
+            BuildableName = "libRCTMIPushModule.a"
+            BlueprintName = "RCTMIPushModule"
+            ReferencedContainer = "container:RCTMIPushModule.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "2BC4EEFA1DBDFDDD00715730"
+            BuildableName = "libRCTMIPushModule.a"
+            BlueprintName = "RCTMIPushModule"
+            ReferencedContainer = "container:RCTMIPushModule.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 22 - 0
ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>SchemeUserState</key>
+	<dict>
+		<key>RCTMIPushModule.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>0</integer>
+		</dict>
+	</dict>
+	<key>SuppressBuildableAutocreation</key>
+	<dict>
+		<key>2BC4EEFA1DBDFDDD00715730</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+	</dict>
+</dict>
+</plist>

+ 177 - 0
ios/RCTMIPushModule/RCTMIPushModule/MiPushSDK.h

@@ -0,0 +1,177 @@
+//
+//  MiPushSDK.h
+//  MiPushSDK
+//
+//  Created by shen yang on 14-3-6.
+//  Copyright (c) 2014年 Xiaomi. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#import <UserNotifications/UserNotifications.h>
+
+@protocol MiPushSDKDelegate <NSObject>
+
+@optional
+
+/**
+ * MiPushSDK 请求结果回调
+ *
+ * MiPushSDK的所有请求的为异步操作, 用户需监听此方法.
+ *
+ * @param
+ *     selector: 请求的方法
+ *     data: 返回结果字典
+ */
+- (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data;
+- (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data;
+
+
+/**
+ * 启用长连接后, 当收到消息是就会回调此方法
+ *
+ * @param
+ *     type: 消息类型
+ *     data: 返回结果字典, 跟apns的消息格式一样
+ */
+- (void)miPushReceiveNotification:(NSDictionary*)data;
+
+@end
+
+@interface MiPushSDK : NSObject
+
+/**
+ * 客户端注册设备
+ * @param 
+ *      delegate: 回调函数
+ *      type: apns推送类型. (Badge, Alert, Sound)
+ *      connect: 是否启动长连接, 它跟APNSs是不同的通道(不管是否启动系统推送, app在前台都可以收到在线或离线消息)
+ */
++ (void)registerMiPush:(id<MiPushSDKDelegate, UNUserNotificationCenterDelegate>)delegate;
++ (void)registerMiPush:(id<MiPushSDKDelegate, UNUserNotificationCenterDelegate>)delegate type:(UIRemoteNotificationType)type;
++ (void)registerMiPush:(id<MiPushSDKDelegate, UNUserNotificationCenterDelegate>)delegate type:(UIRemoteNotificationType)type connect:(BOOL)connect;
+
+/**
+ * 客户端设备注销
+ */
++ (void)unregisterMiPush;
+
+
+/**
+ * 绑定 PushDeviceToken
+ *
+ * NOTE: 有时Apple会重新分配token, 所以为保证消息可达,
+ * 必须在系统application:didRegisterForRemoteNotificationsWithDeviceToken:回调中,
+ * 重复调用此方法. SDK内部会处理是否重新上传服务器.
+ *
+ * @param 
+ *     deviceToken: AppDelegate中,PUSH注册成功后,
+ *                  系统回调didRegisterForRemoteNotificationsWithDeviceToken
+ */
++ (void)bindDeviceToken:(NSData *)deviceToken;
+
+/**
+ * 当同时启动APNs与内部长连接时, 把两处收到的消息合并. 通过miPushReceiveNotification返回
+ */
++ (void)handleReceiveRemoteNotification:(NSDictionary*)userInfo;
+
+/**
+ * 客户端设置别名
+ *
+ * @param
+ *     alias: 别名 (length:128)
+ */
++ (void)setAlias:(NSString *)alias;
+
+/**
+ * 客户端取消别名
+ *
+ * @param
+ *     alias: 别名 (length:128)
+ */
++ (void)unsetAlias:(NSString *)alias;
+
+
+/**
+ * 客户端设置帐号
+ * 多设备设置同一个帐号, 发送消息时多设备可以同时收到
+ *
+ * @param
+ *     account: 帐号 (length:128)
+ */
++ (void)setAccount:(NSString *)account;
+
+/**
+ * 客户端取消帐号
+ *
+ * @param
+ *     account: 帐号 (length:128)
+ */
++ (void)unsetAccount:(NSString *)account;
+
+
+/**
+ * 客户端设置主题
+ * 支持同时设置多个topic, 中间使用","分隔
+ *
+ * @param
+ *     subscribe: 主题类型描述
+ */
++ (void)subscribe:(NSString *)topics;
+
+/**
+ * 客户端取消主题
+ * 支持同时设置多个topic, 中间使用","分隔
+ *
+ * @param
+ *     subscribe: 主题类型描述
+ */
++ (void)unsubscribe:(NSString *)topics;
+
+
+/**
+ * 统计客户端 通过push开启app行为
+ * 如果, 你想使用服务器帮你统计你app的点击率请自行调用此方法
+ * 方法放到:application:didReceiveRemoteNotification:回调中.
+ * @param 
+ *      messageId:Payload里面对应的miid参数
+ */
++ (void)openAppNotify:(NSString *)messageId;
+
+
+/**
+ * NOTE 废弃. 请使用getAllAliasAsync替换
+ * 获取客户端所有设置的别名
+ */
++ (NSArray*)getAllAlias __deprecated;
+
+/**
+ * 获取客户端所有设置的别名
+ */
++ (void)getAllAliasAsync;
+
+/**
+ * NOTE 废弃. 请使用getAllTopicAsync替换
+ * 获取客户端所有订阅的主题
+ */
++ (NSArray*)getAllTopic __deprecated;
+
+/**
+ * 获取客户端所有订阅的主题
+ */
++ (void)getAllTopicAsync;
+
++ (void)getAllAccountAsync;
+
+
+/**
+ * 获取SDK版本号
+ */
++ (NSString*)getSDKVersion;
+
+/**
+ * 获取RegId
+ * 如果没有RegId返回nil
+ */
++ (NSString*)getRegId;
+@end

+ 33 - 0
ios/RCTMIPushModule/RCTMIPushModule/RCTMIPushModule.h

@@ -0,0 +1,33 @@
+//
+//  RCTMIPushModule.h
+//  RCTMIPushModule
+//
+//  Created by zhangzy on 2016/10/24.
+//  Copyright © 2016年 zzy. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#import <UserNotifications/UserNotifications.h>
+#import "RCTBridgeModule.h"
+#import "RCTPushNotificationManager.h"
+#import "MiPushSDK.h"
+
+@interface RCTMIPushModule : NSObject <RCTBridgeModule, MiPushSDKDelegate>
+
++ (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
+
++ (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
+
++ (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+
++ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification;
+
++ (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification;
+
+
++ (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler;
+
++ (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler;
+
+@end

+ 116 - 0
ios/RCTMIPushModule/RCTMIPushModule/RCTMIPushModule.m

@@ -0,0 +1,116 @@
+//
+//  RCTMIPushModule.m
+//  RCTMIPushModule
+//
+//  Created by zhangzy on 2016/10/24.
+//  Copyright © 2016年 zzy. All rights reserved.
+//
+
+#import "RCTMIPushModule.h"
+
+@implementation RCTMIPushModule
+
+RCT_EXPORT_MODULE();
+
+
+RCT_EXPORT_METHOD(setAlias:(NSString *)text)
+{
+    
+    
+    [MiPushSDK setAlias:text];
+}
+
+RCT_EXPORT_METHOD(unsetAlias:(NSString *)text)
+{
+    
+    [MiPushSDK unsetAlias:text];
+}
+
+RCT_EXPORT_METHOD(subscribe:(NSString *)text)
+{
+    
+    [MiPushSDK subscribe:text];
+}
+
+RCT_EXPORT_METHOD(unsubscribe:(NSString *)text)
+{
+    
+    [MiPushSDK unsubscribe:text];
+}
+
+RCT_EXPORT_METHOD(setAccount:(NSString *)text)
+{
+    
+    [MiPushSDK setAccount:text];
+}
+
+RCT_EXPORT_METHOD(unsetAccount:(NSString *)text)
+{
+    
+    [MiPushSDK unsetAccount:text];
+}
+
+- (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data
+{
+    NSLog(@"data:%@", data);
+}
+
+- (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data
+{
+    // 请求失败
+    NSLog(@"error:%@", error);
+}
+
+- (void)miPushReceiveNotification:(NSDictionary *)data {
+    NSLog(@"data2:%@", data);
+}
+
++ (void)application:(id)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+    
+    [MiPushSDK registerMiPush:self];
+    NSLog(@"注册");
+}
+
++ (void)application:(id)application didRegisterUserNotificationSettings:(id)notificationSettings {
+    
+    [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
+}
+
++ (void)application:(id)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
+    
+    NSLog(@"deviceToken:%@", deviceToken);
+    [MiPushSDK bindDeviceToken:deviceToken];
+    [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+}
+
++ (void)application:(id)application didReceiveRemoteNotification:(NSDictionary *)notification {
+    
+    [RCTPushNotificationManager didReceiveRemoteNotification:notification];
+}
+
++ (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+    
+    [RCTPushNotificationManager didReceiveLocalNotification:notification];
+}
+
+// 应用在前台收到通知
++ (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
+    
+    NSDictionary * userInfo = notification.request.content.userInfo;
+    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
+        
+        [RCTPushNotificationManager didReceiveRemoteNotification:userInfo];
+    }
+}
+
+// 点击通知进入应用
++ (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
+    
+    NSDictionary * userInfo = response.notification.request.content.userInfo;
+    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
+        
+        [RCTPushNotificationManager didReceiveRemoteNotification:userInfo];
+    }
+}
+
+@end

BIN
ios/RCTMIPushModule/RCTMIPushModule/libMiPushSDK.a