From 07a2f4493d9478a4247f74a320d84f46a10974dc Mon Sep 17 00:00:00 2001 From: mx1700 Date: Sat, 6 Jul 2019 17:09:58 +0800 Subject: [PATCH] =?UTF-8?q?iOS=20=E6=8E=A8=E9=80=81=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 7 +- ios/Timepill.xcodeproj/project.pbxproj | 79 ++++++++++-- .../xcshareddata/xcschemes/Timepill.xcscheme | 2 +- ios/Timepill/AppDelegate.m | 119 ++++++++++++++++++ ios/Timepill/Info.plist | 42 +++---- ios/Timepill/Timepill.entitlements | 8 ++ src/util/push.js | 20 ++- 7 files changed, 235 insertions(+), 42 deletions(-) create mode 100644 ios/Timepill/Timepill.entitlements diff --git a/index.js b/index.js index 83ec26f..37c5715 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,12 @@ Navigation.events().registerAppLaunchedListener(async () => { } Push.init((msg) => { - console.log("push init: " + msg) + console.log("push init: " + msg); + Push.setAccount("12", (msg) => { + console.log("push setAccount:", JSON.stringify(msg)) + }) + + Push.addReceiveNotificationListener(() => {}); }) }); diff --git a/ios/Timepill.xcodeproj/project.pbxproj b/ios/Timepill.xcodeproj/project.pbxproj index abb5c86..affb72b 100644 --- a/ios/Timepill.xcodeproj/project.pbxproj +++ b/ios/Timepill.xcodeproj/project.pbxproj @@ -5,6 +5,7 @@ }; objectVersion = 46; objects = { + /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -46,9 +47,15 @@ 444B74B0B45F447FA6D25561 /* libRNVectorIcons.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A333F2A12D224289B26028D1 /* libRNVectorIcons.a */; }; 47AE5EA4A39F43CFA279144B /* libRNDeviceInfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B6943EF54DC4C0E8C860C48 /* libRNDeviceInfo.a */; }; 505DDEF9B17C4B93A7D4C4B0 /* libRCTImageResizer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C988095E6478452AAAF73E23 /* libRCTImageResizer.a */; }; + 693ABBB722D093C20044FDF8 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 693ABBB622D093C20044FDF8 /* CoreTelephony.framework */; }; + 693ABBB922D093CE0044FDF8 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 693ABBB822D093CE0044FDF8 /* SystemConfiguration.framework */; }; + 693ABBBB22D093DE0044FDF8 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 693ABBBA22D093DD0044FDF8 /* UserNotifications.framework */; }; + 693ABBBD22D093EC0044FDF8 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 693ABBBC22D093EC0044FDF8 /* libz.tbd */; }; + 693ABBBF22D093FA0044FDF8 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 693ABBBE22D093FA0044FDF8 /* libsqlite3.0.tbd */; }; 6CA03C7B6F034CF5B2ECC3E5 /* libRNVectorIcons-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FC4807EA1FA42A4A55BDAE5 /* libRNVectorIcons-tvOS.a */; }; 6CAEBF678D2F4D3A8D88B88A /* EvilIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = CC35BDC2C50846E0A4F98D35 /* EvilIcons.ttf */; }; 71E72460768C4C9EB73C5050 /* MaterialCommunityIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0D4DF9EF3F764CD0BF997FD6 /* MaterialCommunityIcons.ttf */; }; + 7497C6D0D64344B197447DC7 /* libRCTXGPushModule.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 62865F98E711415DBA4DAFF9 /* libRCTXGPushModule.a */; }; 7CDD27C257FA4106B76D549E /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C558ABC6E5C94D939958E5F9 /* FontAwesome.ttf */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 9678DE108DEC4C5A9D92EA1D /* libimageCropPicker.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 996469B8096342559A8F98D6 /* libimageCropPicker.a */; }; @@ -63,7 +70,6 @@ ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED297162215061F000B7C4FE /* JavaScriptCore.framework */; }; ED2971652150620600B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED2971642150620600B7C4FE /* JavaScriptCore.framework */; }; F343A722A8DB46C79081F2A0 /* Entypo.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 81F0243DD71F467A964CAD89 /* Entypo.ttf */; }; - 85CC1DC101F845E7A6C77B00 /* libRCTXGPushModule.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E259EF5D4BD4D388D1C513C /* libRCTXGPushModule.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -382,6 +388,13 @@ remoteGlobalIDString = 2D2A28201D9B03D100D4039D; remoteInfo = "RCTAnimation-tvOS"; }; + 693ABBB422D0939A0044FDF8 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 461950EE4FD949249DD2937B /* RCTXGPushModule.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = B779C03A206113DE0039BF59; + remoteInfo = RCTXGPushModule; + }; 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; @@ -452,9 +465,17 @@ 4156314A2297CFA5009EB583 /* RSKImageCropper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RSKImageCropper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4156314E2297CFBE009EB583 /* QBImagePicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = QBImagePicker.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4166A0DE22895B4B0086277D /* ReactNativeNavigation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ReactNativeNavigation.xcodeproj; path = "../node_modules/react-native-navigation/lib/ios/ReactNativeNavigation.xcodeproj"; sourceTree = ""; }; + 461950EE4FD949249DD2937B /* RCTXGPushModule.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTXGPushModule.xcodeproj; path = "../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule.xcodeproj"; sourceTree = ""; }; 4B6943EF54DC4C0E8C860C48 /* libRNDeviceInfo.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNDeviceInfo.a; sourceTree = ""; }; 4DC49BDD3EFD4FA997BEEF58 /* Zocial.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Zocial.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Zocial.ttf"; sourceTree = ""; }; 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; + 62865F98E711415DBA4DAFF9 /* libRCTXGPushModule.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTXGPushModule.a; sourceTree = ""; }; + 693ABB6B22D0925E0044FDF8 /* Timepill.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = Timepill.entitlements; path = Timepill/Timepill.entitlements; sourceTree = ""; }; + 693ABBB622D093C20044FDF8 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; + 693ABBB822D093CE0044FDF8 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + 693ABBBA22D093DD0044FDF8 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + 693ABBBC22D093EC0044FDF8 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 693ABBBE22D093FA0044FDF8 /* libsqlite3.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.0.tbd; path = usr/lib/libsqlite3.0.tbd; sourceTree = SDKROOT; }; 6D8788EB66CB42AAAE311EF6 /* Feather.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Feather.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Feather.ttf"; sourceTree = ""; }; 784C7C58E2B04EECBD71EF5E /* libRNDeviceInfo-tvOS.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = "libRNDeviceInfo-tvOS.a"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; @@ -477,8 +498,6 @@ ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; }; FE0D7FAFEDE44E168687B4B2 /* RNCAsyncStorage.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNCAsyncStorage.xcodeproj; path = "../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.xcodeproj"; sourceTree = ""; }; - 4C4A99AB1DC742A48D0A1515 /* RCTXGPushModule.xcodeproj */ = {isa = PBXFileReference; name = "RCTXGPushModule.xcodeproj"; path = "../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; - 3E259EF5D4BD4D388D1C513C /* libRCTXGPushModule.a */ = {isa = PBXFileReference; name = "libRCTXGPushModule.a"; path = "libRCTXGPushModule.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -494,6 +513,11 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 693ABBBF22D093FA0044FDF8 /* libsqlite3.0.tbd in Frameworks */, + 693ABBBD22D093EC0044FDF8 /* libz.tbd in Frameworks */, + 693ABBBB22D093DE0044FDF8 /* UserNotifications.framework in Frameworks */, + 693ABBB922D093CE0044FDF8 /* SystemConfiguration.framework in Frameworks */, + 693ABBB722D093C20044FDF8 /* CoreTelephony.framework in Frameworks */, 4166A0E722895B5C0086277D /* libReactNativeNavigation.a in Frameworks */, ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */, ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */, @@ -516,7 +540,7 @@ 9678DE108DEC4C5A9D92EA1D /* libimageCropPicker.a in Frameworks */, 4156314F2297CFBE009EB583 /* QBImagePicker.framework in Frameworks */, 35DCFF50947D4FCBBF5A8921 /* libRNFetchBlob.a in Frameworks */, - 85CC1DC101F845E7A6C77B00 /* libRCTXGPushModule.a in Frameworks */, + 7497C6D0D64344B197447DC7 /* libRCTXGPushModule.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -631,6 +655,7 @@ 13B07FAE1A68108700A75B9A /* Timepill */ = { isa = PBXGroup; children = ( + 693ABB6B22D0925E0044FDF8 /* Timepill.entitlements */, 008F07F21AC5B25A0029DE68 /* main.jsbundle */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.m */, @@ -668,6 +693,11 @@ 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { isa = PBXGroup; children = ( + 693ABBBE22D093FA0044FDF8 /* libsqlite3.0.tbd */, + 693ABBBC22D093EC0044FDF8 /* libz.tbd */, + 693ABBBA22D093DD0044FDF8 /* UserNotifications.framework */, + 693ABBB822D093CE0044FDF8 /* SystemConfiguration.framework */, + 693ABBB622D093C20044FDF8 /* CoreTelephony.framework */, ED297162215061F000B7C4FE /* JavaScriptCore.framework */, ED2971642150620600B7C4FE /* JavaScriptCore.framework */, 2D16E6891FA4F8E400B85C8A /* libReact.a */, @@ -719,6 +749,7 @@ C988095E6478452AAAF73E23 /* libRCTImageResizer.a */, 996469B8096342559A8F98D6 /* libimageCropPicker.a */, B2E8AA4B1D85497E86DAA92C /* libRNFetchBlob.a */, + 62865F98E711415DBA4DAFF9 /* libRCTXGPushModule.a */, ); name = "Recovered References"; sourceTree = ""; @@ -757,6 +788,14 @@ name = Products; sourceTree = ""; }; + 693ABBB122D0939A0044FDF8 /* Products */ = { + isa = PBXGroup; + children = ( + 693ABBB522D0939A0044FDF8 /* libRCTXGPushModule.a */, + ); + name = Products; + sourceTree = ""; + }; 78C398B11ACF4ADC00677621 /* Products */ = { isa = PBXGroup; children = ( @@ -788,7 +827,7 @@ DE970E03BCC84CE8A281A103 /* RCTImageResizer.xcodeproj */, BDBA91D5680B4ACA83A7844B /* imageCropPicker.xcodeproj */, 99151F1A82BD48E0B5416458 /* RNFetchBlob.xcodeproj */, - 4C4A99AB1DC742A48D0A1515 /* RCTXGPushModule.xcodeproj */, + 461950EE4FD949249DD2937B /* RCTXGPushModule.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -945,8 +984,17 @@ TargetAttributes = { 00E356ED1AD99517003FC87E = { CreatedOnToolsVersion = 6.2; + DevelopmentTeam = 96T8KJDKQ3; TestTargetID = 13B07F861A680F5B00A75B9A; }; + 13B07F861A680F5B00A75B9A = { + DevelopmentTeam = 96T8KJDKQ3; + SystemCapabilities = { + com.apple.Push = { + enabled = 1; + }; + }; + }; 2D02E47A1E0B4A5D006451C7 = { CreatedOnToolsVersion = 8.2.1; ProvisioningStyle = Automatic; @@ -1023,6 +1071,10 @@ ProductGroup = 139FDEE71B06529A00C62182 /* Products */; ProjectRef = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; }, + { + ProductGroup = 693ABBB122D0939A0044FDF8 /* Products */; + ProjectRef = 461950EE4FD949249DD2937B /* RCTXGPushModule.xcodeproj */; + }, { ProductGroup = 146834001AC3E56700842450 /* Products */; ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */; @@ -1360,6 +1412,13 @@ remoteRef = 5E9157341DD0AC6500FF2AA8 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 693ABBB522D0939A0044FDF8 /* libRCTXGPushModule.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libRCTXGPushModule.a; + remoteRef = 693ABBB422D0939A0044FDF8 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -1526,6 +1585,7 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + DEVELOPMENT_TEAM = 96T8KJDKQ3; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -1570,6 +1630,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; + DEVELOPMENT_TEAM = 96T8KJDKQ3; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", @@ -1609,8 +1670,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = Timepill/Timepill.entitlements; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; + DEVELOPMENT_TEAM = 96T8KJDKQ3; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/../node_modules/react-native-navigation/ios", "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", @@ -1628,7 +1691,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = "net.timepill.diary-app"; PRODUCT_NAME = Timepill; VERSIONING_SYSTEM = "apple-generic"; }; @@ -1638,7 +1701,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = Timepill/Timepill.entitlements; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 96T8KJDKQ3; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/../node_modules/react-native-navigation/ios", "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", @@ -1656,7 +1721,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = "net.timepill.diary-app"; PRODUCT_NAME = Timepill; VERSIONING_SYSTEM = "apple-generic"; }; diff --git a/ios/Timepill.xcodeproj/xcshareddata/xcschemes/Timepill.xcscheme b/ios/Timepill.xcodeproj/xcshareddata/xcschemes/Timepill.xcscheme index 0a54ae1..e4233da 100644 --- a/ios/Timepill.xcodeproj/xcshareddata/xcschemes/Timepill.xcscheme +++ b/ios/Timepill.xcodeproj/xcshareddata/xcschemes/Timepill.xcscheme @@ -103,7 +103,7 @@ + isEnabled = "NO"> diff --git a/ios/Timepill/AppDelegate.m b/ios/Timepill/AppDelegate.m index 3c58aad..a4f268e 100644 --- a/ios/Timepill/AppDelegate.m +++ b/ios/Timepill/AppDelegate.m @@ -11,14 +11,133 @@ #import #import +#import "XGPush.h" +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 +#import +#endif +#import "RCTXGPushModule.h" + +@interface AppDelegate () +@end + @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + [[XGPush defaultManager] setEnableDebug:YES]; + XGNotificationAction *action1 = [XGNotificationAction actionWithIdentifier:@"xgaction001" title:@"xgAction1" options:XGNotificationActionOptionNone]; + XGNotificationAction *action2 = [XGNotificationAction actionWithIdentifier:@"xgaction002" title:@"xgAction2" options:XGNotificationActionOptionDestructive]; + XGNotificationCategory *category = [XGNotificationCategory categoryWithIdentifier:@"xgCategory" actions:@[action1, action2] intentIdentifiers:@[] options:XGNotificationCategoryOptionNone]; + XGNotificationConfigure *configure = [XGNotificationConfigure configureNotificationWithCategories:nil types:XGUserNotificationTypeAlert|XGUserNotificationTypeBadge|XGUserNotificationTypeSound]; + [[XGPush defaultManager] setNotificationConfigure:configure]; + [[XGPush defaultManager] startXGWithAppID:2200337125 appKey:@"IN15RCD511ZK" delegate:self]; + [[XGPush defaultManager] setXgApplicationBadgeNumber:0]; + [[XGPush defaultManager] reportXGNotificationInfo:launchOptions]; + NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions]; return YES; } +-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ + NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error); + [[NSNotificationCenter defaultCenter] postNotificationName:@"registerDeviceFailed" object:nil]; +} + +/** + 收到通知的回调 + + @param application UIApplication 实例 + @param userInfo 推送时指定的参数 + */ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { + NSLog(@"[XGDemo] receive Notification"); + [[XGPush defaultManager] reportXGNotificationInfo:userInfo]; + NSLog(@"ios 9 "); + if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive) + { + //NSLog(@"didReceiveRemoteNotification:APP在前台运行时,不做处理"); + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo]; + }//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面 + else if([UIApplication sharedApplication].applicationState == UIApplicationStateInactive){ + // 取得 APNs 标准信息内容 + //NSLog(@"didReceiveRemoteNotification:APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面"); + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotification object:userInfo]; + } + +} + +/** + 收到静默推送的回调 + + @param application UIApplication 实例 + @param userInfo 推送时指定的参数 + @param completionHandler 完成回调 + */ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + NSLog(@"[XGDemo] receive slient Notification"); + NSLog(@"[XGDemo] userinfo %@", userInfo); + [[XGPush defaultManager] reportXGNotificationInfo:userInfo]; + + if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive) + { + //NSLog(@"didReceiveRemoteNotification:APP在前台运行时,不做处理"); + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo]; + }//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面 + else if([UIApplication sharedApplication].applicationState == UIApplicationStateInactive){ + // 取得 APNs 标准信息内容 + //NSLog(@"didReceiveRemoteNotification:APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面"); + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotification object:userInfo]; + } + + completionHandler(UIBackgroundFetchResultNewData); +} + + +// iOS 10 新增 API +// iOS 10 会走新 API, iOS 10 以前会走到老 API +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 +// App 用户点击通知 +// App 用户选择通知中的行为 +// App 用户在通知中心清除消息 +// 无论本地推送还是远程推送都会走这个回调 +- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { + NSLog(@"[XGDemo] click notification"); + // if ([response.actionIdentifier isEqualToString:@"xgaction001"]) { + // NSLog(@"click from Action1"); + // } else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) { + // NSLog(@"click from Action2"); + // } + + [[XGPush defaultManager] reportXGNotificationResponse:response]; + NSDictionary * userInfo = response.notification.request.content.userInfo; + // if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { + [[XGPush defaultManager] reportXGNotificationInfo:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotification object:userInfo]; + completionHandler(); +} + +// App 在前台弹通知需要调用这个接口 +- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { + [[XGPush defaultManager] reportXGNotificationInfo:notification.request.content.userInfo]; + NSLog(@"xgPushUserNotificationCenter"); + NSDictionary * userInfo = notification.request.content.userInfo; + // if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { + [[XGPush defaultManager] reportXGNotificationInfo:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo]; + completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert); +} +#endif + +#pragma mark - XGPushDelegate +- (void)xgPushDidFinishStart:(BOOL)isSuccess error:(NSError *)error { + NSLog(@"%s, result %@, error %@", __FUNCTION__, isSuccess?@"OK":@"NO", error); +} + +- (void)xgPushDidFinishStop:(BOOL)isSuccess error:(NSError *)error { + NSLog(@"%s, result %@, error %@", __FUNCTION__, isSuccess?@"OK":@"NO", error); +} + @end diff --git a/ios/Timepill/Info.plist b/ios/Timepill/Info.plist index f2e8b13..6066095 100644 --- a/ios/Timepill/Info.plist +++ b/ios/Timepill/Info.plist @@ -2,14 +2,10 @@ - NSCameraUsageDescription - - NSPhotoLibraryUsageDescription - CFBundleDevelopmentRegion en CFBundleDisplayName - Timepill + 胶囊日记 CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -28,22 +24,6 @@ 1 LSRequiresIPhoneOS - NSLocationWhenInUseUsageDescription - - UILaunchStoryboardName - LaunchScreen - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - NSAppTransportSecurity NSAllowsArbitraryLoads @@ -57,6 +37,12 @@ + NSCameraUsageDescription + + NSLocationWhenInUseUsageDescription + + NSPhotoLibraryUsageDescription + UIAppFonts Entypo.ttf @@ -71,5 +57,19 @@ Octicons.ttf Zocial.ttf + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarStyle + UIStatusBarStyleLightContent + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UIViewControllerBasedStatusBarAppearance + diff --git a/ios/Timepill/Timepill.entitlements b/ios/Timepill/Timepill.entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/ios/Timepill/Timepill.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/src/util/push.js b/src/util/push.js index 53869ea..53a910e 100644 --- a/src/util/push.js +++ b/src/util/push.js @@ -3,7 +3,7 @@ import XGPushModule from 'react-native-smart-xgpush'; const XGPushNativeModules = NativeModules.XGPushModule; function init(cb) { - if(Platform.OS ==='android'){ + if(Platform.OS === 'android'){ XGPushNativeModules.enableDebug(true); XGPushModule.notifyJSDidLoad(() => { XGPushModule.registerPush(); @@ -13,9 +13,6 @@ function init(cb) { } else { cb(); } - setAccount("12", (r) => { - console.log('setAccount:', r) - }) } function initOtherPush() { @@ -24,14 +21,11 @@ function initOtherPush() { const appId = '2882303761517764099'; const appKey = '5341776464099'; XGPushNativeModules.initXiaomi(appId, appKey); - - addReceiveNotificationListener(null); } function setAccount(uid, cb) { if(Platform.OS === 'ios'){ XGPushModule.setAccount(uid,cb); - }else{ XGPushModule.bindAccount(uid,cb); } @@ -39,13 +33,14 @@ function setAccount(uid, cb) { function addReceiveNotificationListener(cb) { XGPushModule.addReceiveNotificationListener((map) => { - console.log("[ReceiveNotification]", map) + console.log("[ReceiveNotification]", map); + cb(map); }); - XGPushModule.addReceiveOpenNotificationListener((msg) => { - console.log("[addReceiveOpenNotificationListener]", msg) - - }) + // XGPushModule.addReceiveOpenNotificationListener((msg) => { + // console.log("[addReceiveOpenNotificationListener]", msg) + // + // }) } @@ -53,4 +48,5 @@ function addReceiveNotificationListener(cb) { export default { init, setAccount, + addReceiveNotificationListener, } \ No newline at end of file