プッシュ通知に取り組んでいます。プッシュ通知用のAPIがありますが、ios 10バージョンを使用してcode.iを実装する方法はありません。Apiを使用したプッシュ通知
0
A
答えて
1
我々は新しいフレームワークといくつかのコードを追加する必要がIOS 10を使用する場合
STEP:1
iOS 10から、私たちはUserNotificationsフレームワークとdelegat.Firstを追加する必要があります。
STEP:2
デリゲートUNUserNotificationCenterDelegate今
を追加appDelegate.h
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
appDeleg ate.m
STEP:3
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.applicationIconBadgeNumber = 0;
if(SYSTEM_VERSION_LESS_THAN(@"10.0"))
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if(!error)
{
[[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications
NSLog(@"Push registration success.");
}
else
{
NSLog(@"Push registration FAILED");
NSLog(@"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription);
NSLog(@"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion);
}
}];
}
return YES;
}
STEP:4
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// custom stuff we do to register the device with our AWS middleman
NSString *strToken = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
strToken = [strToken stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"content---%@", strToken);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"your url here"]]];
[request setHTTPMethod:@"POST"];
//Pass The String to server
NSString *userUpdate =[NSString stringWithFormat:@"device_token=%@",strToken,nil];
//Check The Value what we passed
NSLog(@"the data Details is =%@", userUpdate);
//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
//Apply the data to the body
[request setHTTPBody:data1];
//Create the response and Error
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if(httpResponse.statusCode == 200)
{
if(httpResponse.statusCode == 200)
{
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"The response is - %@",responseDictionary);
}
else
{
NSLog(@"Error");
}
}
else
{
NSLog(@"faield to connect");
}
}];
[dataTask resume];
}
STEP:5
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void
(^)(UIBackgroundFetchResult))completionHandler
{
// iOS 10 will handle notifications through other methods
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0"))
{
NSLog(@"iOS version >= 10. Let NotificationCenter handle this one.");
// set a member variable to tell the new delegate that this is background
return;
}
NSLog(@"HANDLE PUSH, didReceiveRemoteNotification: %@", userInfo);
// custom code to handle notification content
if([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
{
NSLog(@"INACTIVE");
completionHandler(UIBackgroundFetchResultNewData);
}
else if([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
NSLog(@"BACKGROUND");
completionHandler(UIBackgroundFetchResultNewData);
}
else
{
NSLog(@"FOREGROUND");
completionHandler(UIBackgroundFetchResultNewData);
}
}
//OR
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) {
}];
NSLog(@"Received notification: %@", userInfo);
if ([userInfo count]!=0)
{
NSMutableArray *notify=[[NSMutableArray alloc]init];
NSMutableArray *mutableRetrievedDictionary;
mutableRetrievedDictionary = [[NSUserDefaults standardUserDefaults] objectForKey:@"noyificationcount"] ;
NSMutableArray *deviealert = [[NSUserDefaults standardUserDefaults] objectForKey:@"noyificationcount"] ;
deviealert=[[NSMutableArray alloc]init];
[notify addObject: [[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
NSLog(@"notification is - %@", notify);
NSString *strAlertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
NSLog(@"my message-- %@",strAlertValue);
deviealert=[notify mutableCopy];
NSLog(@"new...%@",deviealert);
[[ NSUserDefaults standardUserDefaults]setObject:deviealert forKey:@"noyificationcount" ];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(@"dev.....%@",deviealert);
[UIApplication sharedApplication].applicationIconBadgeNumber+=1;
}
}
STEP:6
フォアグラウンド状態に対する
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog(@"Handle push from foreground");
// custom code to handle push while app is in the foreground
NSLog(@"%@", notification.request.content.userInfo);
}
STEP:7
背景状態について
2
iOS 10でプッシュ通知を実装する方法については、下のリンクから完全に理解できます。ここでは、リンクの下に参照してくださいXCodeの8に同じことを実装するための手順を見つける:Push notification issue with iOS 10
+0
ここでjson apiが実装されています –
関連する問題
- 1. コードバスを使用したFireBaseプッシュ通知
- 2. プロキシを使用したプッシュ通知
- 3. RHMAPを使用したプッシュ通知
- 4. レスポンスを使用したASP.NETプッシュ通知
- 5. GCMを使用したiOSプッシュ通知
- 6. cURLを使用したAppleプッシュ通知
- 7. WiFiを使用したプッシュ通知
- 8. mosquittoを使用したiphoneプッシュ通知
- 9. Railsサーバーを使用したプッシュ通知
- 10. XamarinフォームAzure通知ハブを使用したプッシュ通知
- 11. 削除プッシュ通知サーバーAPI
- 12. プッシュ通知用サーバー?
- 13. Azure通知ハブを使用したXamarinアプリケーションからのプッシュ通知の送信
- 14. onesignalを使用したパーソナライズされたプッシュ通知の送信
- 15. ブラックベリーのプッシュ通知でwifiを使用
- 16. PhoneGapを使用したFirebaseプッシュ通知cordova-plugin-fcmを使用したビルド
- 17. sinonを使ったプッシュ通知のスチューブ
- 18. Laravelプッシュ通知使っdavibennun/laravelプッシュ通知パッケージ
- 19. イオンプッシュを使用した複数のプッシュ通知
- 20. WebViewとJavascriptを使用したプッシュ通知
- 21. UrbanAirship iOS SDKを使用したプッシュ通知のカスタムメソッド
- 22. pyapnsを使用したPythonでのSafariプッシュ通知
- 23. iOS - プッシュ通知を使用したApp Storeの送信
- 24. ノードJSを使用したAWS SNSプッシュ通知
- 25. ノードjsとポリマーウェブアプリケーションを使用したFirebaseプッシュ通知
- 26. Google Cloud機能とGoogle Firebaseを使用したプッシュ通知
- 27. モバイルでのプッシュ通知Firebaseを使用したXamarin
- 28. XMPPを使用したプッシュ通知とC2MDのロードマップ
- 29. Flexモバイル開発を使用したIphone Appのプッシュ通知
- 30. バックグラウンド処理を使用したIonic2プッシュ通知
私はjson apiを持っていますが、私はAPIを呼び出します –
コードを投稿してください。私はこれのために多くの問題に直面しています。 –
jsonコードでdidRecieveRemoteNotificationsを呼び出すと、自動的にpushnotificationsが返されます。配列や文字列を取得すると、何かがそこにあります。 –