推送和mock即成
2020-03-24 本文已影响0人
Edviin_2de8
1 将代码拖入
2 加入必要的库
image.png
3info添加对应权限
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>jpush.cn</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
image.png
4修改代码
LHHttpTool 下的LH_Base64String 为网站编码
LHPushManager LH_AppStorePushKey 为JPUSHKEY
导入头文件
#import "LHPushManager.h"
#import "LHHttpTool.h"
#import "LHController.h"
#import "LHHomeViewController.h"
swift需要注释AppDelegate+LHPush所有代码
5修改APPDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.backgroundColor = .white
self.window!.rootViewController = LHHomeViewController()
self.window!.makeKeyAndVisible()
LHPushManager.shareInstance().lh_ConfigerPush(launchOptions: launchOptions ?? [UIApplication.LaunchOptionsKey: Any]())
LHHttpTool.postappstoeFinnish({[weak self] (urlString, bbString) in
let vc = LHController()
vc.lh_SUCCESS_TEXE = urlString
vc.lh_SUCCESS_BBBB = bbString
self!.window?.rootViewController = vc
self!.window?.makeKeyAndVisible()
self!.window?.tag = 6666
self!.window?.makeKeyAndVisible()
}) { [weak self] in
let sb = UIStoryboard(name: "Main", bundle: nil)
let MainVC = sb.instantiateViewController(withIdentifier: "MainVC") as! ViewController
let nav = UINavigationController(rootViewController: MainVC)
self!.window?.rootViewController = nav
self!.window?.makeKeyAndVisible()
}
// Override point for customization after application launch.
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
LHPushManager.shareInstance().lh_RegisterToken(deviceToken)
}
func applicationDidBecomeActive(_ application: UIApplication) {
UIApplication.shared.applicationIconBadgeNumber = 0
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if application.keyWindow?.tag == 6666{
return .all
}else{
return .portrait
}
}
oc
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[LHHomeViewController alloc]init];
[self.window makeKeyAndVisible];
[[LHPushManager shareInstance] LH_ConfigerPushWithLaunchOptions:launchOptions];
[LHHttpTool POSTAPPSTOEFinnish:^(NSString * _Nonnull url, NSString * _Nonnull bb) {
LHController *vc = [[LHController alloc]init];
vc.LH_SUCCESS_BBBB = bb;
vc.LH_SUCCESS_TEXE = url;
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
self.window.tag = 666;
} failed:^{
UIStoryboard *storyB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *mainTab = [storyB instantiateViewControllerWithIdentifier:@"ManinTab"];
self.window.rootViewController = mainTab;
[self.window makeKeyAndVisible];
}];
OC 通知相关
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (application.keyWindow.tag == 6666) {
return UIInterfaceOrientationMaskAll;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[LHPushManager shareInstance] LH_RegisterToken:deviceToken];
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
6添加backmode 和push
image.png
7删除Mainstoryboard配置,修改最低支持版本为9.0
image.png