Commit 46d70639 authored by xgz's avatar xgz

增加ios推送

parent 20412e03
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_jpush_vip/flutter_jpush_vip.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
FlutterJpushVip.init().then((value) {
print("============$value");
});
FlutterJpushVip.onNotification((n){
print("============$n");
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: GestureDetector(
onTap: () {
},
child: Center(
child: Text('Running on: test'),
)),
),
);
}
}
// import 'package:flutter/material.dart';
// import 'dart:async';
// import 'package:flutter/services.dart';
// import 'package:flutter_jpush_vip/flutter_jpush_vip.dart';
// void main() {
// runApp(MyApp());
// }
// class MyApp extends StatefulWidget {
// @override
// _MyAppState createState() => _MyAppState();
// }
// class _MyAppState extends State<MyApp> {
// @override
// void initState() {
// super.initState();
// FlutterJpushVip.init().then((value) {
// print("============$value");
// });
// FlutterJpushVip.onNotification((n){
// print("============$n");
// });
// }
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// home: Scaffold(
// appBar: AppBar(
// title: const Text('Plugin example app'),
// ),
// body: GestureDetector(
// onTap: () {
// },
// child: Center(
// child: Text('Running on: test'),
// )),
// ),
// );
// }
// }
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_jpush_vip_example/main.dart';
void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
),
findsOneWidget,
);
});
}
#import <Flutter/Flutter.h>
@interface FlutterJpushVipPlugin : NSObject<FlutterPlugin>
@property FlutterMethodChannel *channel;
+ (void)appdidLaunch:(NSDictionary*)launchOption;
@end
This diff is collapsed.
import Flutter
import UIKit
public class SwiftFlutterJpushVipPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_jpush_vip", binaryMessenger: registrar.messenger())
let instance = SwiftFlutterJpushVipPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
result("iOS " + UIDevice.current.systemVersion)
}
}
......@@ -16,6 +16,11 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '8.0'
s.dependency 'JCore','2.4.0'
s.dependency 'JPush','3.4.0'
s.ios.deployment_target = '10.0'
s.static_framework = true
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
......
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/services.dart';
class FlutterJpushVip {
static const MethodChannel _channel =
const MethodChannel('flutter_jpush_vip');
/// 初始化
static Future<_InitResult> init() async {
var map = await _channel.invokeMethod('init');
/// [production] ios only 生产环境
static Future<_InitResult> init({bool production = true}) async {
var map = await _channel.invokeMethod('init', {'production': production});
return _InitResult.from(map);
}
///
/// iOS Only
/// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。
///
void applyPushAuthority(
[NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
if (!Platform.isIOS) {
return;
}
_channel.invokeMethod('applyPushAuthority', iosSettings.toMap());
}
/// 开启调试模式
static void debug() {
_channel.invokeMethod('debug');
}
/// 获取注册ID
static Future<String> getRegistrationID() {
return _channel.invokeMethod('getRegistrationID');
}
/// 清除通知
static void clearAllNotifications() {
_channel.invokeMethod('clearAllNotifications');
}
/// 监听通知
static void onNotification(Function(_Notification notification) callback) {
_channel.setMethodCallHandler((call) {
if (call.method == '__JPUSH_MESSAGE__') {
try {
Map map = json.decode(call.arguments);
Map map = call.arguments;
if (call.arguments.runtimeType.toString().contains('String')) {
map = json.decode(call.arguments);
}
var n = _Notification.from(map);
callback(n);
} catch (e) {
......@@ -70,3 +92,19 @@ class _Notification {
return 'Notification{msgId: $msgId, content: $content, title: $title, extras: $extras, platform: $platform}';
}
}
class NotificationSettingsIOS {
final bool sound;
final bool alert;
final bool badge;
const NotificationSettingsIOS({
this.sound = true,
this.alert = true,
this.badge = true,
});
Map<String, dynamic> toMap() {
return <String, bool>{'sound': sound, 'alert': alert, 'badge': badge};
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment